未加入android:supportsRtl=“true” 阿拉伯语(RTL)的示例.
加入该属性的英文(LTR)语言效果.
加入该属性的阿拉伯语(RTL)语言效果.
1 2 3 4 5 6 7 8 | <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tvOne" android:paddingLeft="100dp" android:background="#ccefc8" android:text="@string/share" /> |
---|
阿拉伯语下的效果图为
如上面所说,RTL语言是以右作为开始,所以paddingLeft明显不符合规则. 那我们使用paddingStart看一下.
1 2 3 4 5 6 7 8 | <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tvOne" android:paddingStart="100dp" android:background="#ccefc8" android:text="@string/share" /> |
---|
上述代码在阿拉伯语下的效果图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.rtldemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" android:supportsRtl="true" > <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | package com.example.rtldemo; import java.util.ArrayList; import java.util.Locale; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; public class MainActivity extends Activity { private static final String LOGTAG = "MainActivity"; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_layout); ListView listView = (ListView)findViewById(R.id.lvOne); int layoutDirection = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()); Log.i(LOGTAG, "onCreate layoutDirection=" + layoutDirection); TestAdapter adapter = new TestAdapter(); adapter.mData.add(getResources().getString(R.string.share)); adapter.mData.add(getResources().getString(R.string.share)); listView.setAdapter(adapter); } class TestAdapter extends BaseAdapter { ArrayList<String> mData = new ArrayList<String>(); @Override public int getCount() { return mData.size(); } @Override public String getItem(int position) { return mData.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = null; view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.listview_item, null); ImageView imgView = (ImageView)view.findViewById(R.id.itemImageView); imgView.setImageResource(R.drawable.ic_launcher); TextView textView = (TextView)view.findViewById(R.id.itemTextView); textView.setText(mData.get(position)); return view; } } } |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/btnOne" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/share" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tvOne" android:paddingStart="100dp" android:background="#ccefc8" android:text="@string/share" /> <EditText android:id="@+id/etOne" android:layout_width="100dp" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <CheckBox android:layout_width="100dp" android:layout_height="100dp" /> <TextView android:layout_width="wrap_content" android:layout_height="100dp" android:text="@string/share" /> </LinearLayout> <ListView android:id="@+id/lvOne" android:layout_width="match_parent" android:layout_height="wrap_content" ></ListView> </LinearLayout> |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ImageView android:id="@+id/itemImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/itemTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> |
---|