1. 程式人生 > >Android,在LinearLayout中動態新增TextView,幾點疑問

Android,在LinearLayout中動態新增TextView,幾點疑問

第一條:
是可以在xml中定義text的,比如定義textview layout檔案如下:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:textSize="@dimen/textsize"
android:ellipsize="end"
android:layout_height="@dimen/height_22">
</TextView>


那麼在程式碼裡可以用inflater把該xml化成view,寫法大致如下:
TextView text1 = (TextView) inflater.inflate(this, R.layout.text, null);

第二條:
兩個text佔一行的實現方式就多了,
比如可以在xml中把兩個textview 放在一個horizontal的linearLayout中,或是使用 RelativeLayout放在同一行即可,關鍵是控制好兩個textview都不換行就行。

第三條:
分割線的實現方式也有幾種。
比如兩個textview控制元件中有個imageview控制元件,imageview用線的圖片。
或者用textview的drawableLeft drawableRight屬性,把圖片設定成前一個textview的drawableRight或是設定成後一個textview的drawableLeft,線使用圖片或者自己定義都可以的。