?因為剛開始學習android,多少對控件以及詳細的參數配置不熟悉,加之經驗少,導致今天因為一個RadioButton無法顯示搞了半個小時。
先看配置源碼:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/radioButtonTitle" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <RadioGroup android:id="@+id/sexRG" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <RadioButton android:id="@+id/maleRB" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <RadioButton android:id="@+id/femaleRB" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RadioGroup> <TextView android:id="@+id/radioButton_resultTV" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
??
上面所有控件的內容都是在Activity中通過setText配置的。
后來逐個排查的時候,猛然發現XML配置文件中id叫radioButtonTitle的TextView控件的寬度和高度都是fill_parent的fill_parent表示占據當前父窗體的全部空間,所以應該說RadioButton是存在的,只是它被擠出屏幕了,TextView的水平弄成fill_parent(水平填滿),垂直高度弄成wrap_content(文本內容的高度)即可:
<TextView android:id="@+id/radioButtonTitle" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
?
這種錯誤犯了一次,終生受用。希望對Android新人朋友有所幫助。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
