AndroidのTextView之CompoundDrawable那些坑

來源:互聯網
上載者:User

標籤:

    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那些坑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.