標籤:
TextView有幾個屬性android:drawableXXX,通常是在環繞文字周邊顯示一個映像,但是這有個坑就是文字和圖片可能會對不齊。
縱使你設定gravity還是layout_gravity=center都沒有任何效果。
一般在app的底部導覽列,會用RadioButton去實現。RadioGroup應該是一個線性布局,支援oratation屬性可以橫的也可以豎得排列。
既然是底部導覽列,一般都會設定橫向布局,然後每一個RadioButton把weight屬性同時設為1,layout_width設為match_parent,然後再
把button屬性設定@null,甚至把背景屬性設定為空白的或者透明的,還是沒有效果的。
的代碼:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="?android:attr/listChoiceIndicatorSingle" android:text="@string/hello_world" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:drawableTop="?android:attr/listChoiceIndicatorSingle" android:text="@string/hello_world" /> <TextView android:layout_width="100dp" android:layout_height="wrap_content" android:drawableTop="?android:attr/listChoiceIndicatorSingle" android:text="@string/hello_world" /> </LinearLayout>
看到上面的和代碼,只有寬度設定為wrap_content才能置中。再試著把gravity設定為center,結果你到會大吃一驚。
設定置中文字還在與表徵圖的中間靠左對齊,太坑了。
我信心滿滿的把屬性都去掉,然後一不小心又沒對齊了?
如果是一個字用wrap竟然也沒用,加上gravity這個我字就偏右一點,不加就偏左一點。
如果用線性布局去裝一個ImageView和TextView編譯器還提示你用TextView的drawablexx去實現。。。。
AndroidのTextView之CompoundDrawable那些坑