[問題] linearlayout的問題

看板AndroidDev作者 (台灣真是個寶島... 屁!)時間9年前 (2016/05/17 16:16), 9年前編輯推噓0(007)
留言7則, 3人參與, 最新討論串1/1
下面是我的layout程式碼 <?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"> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/mybut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAllCaps="false" android:text="@string/button"/> <TextView android:id="@+id/mytext" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/text"/> </LinearLayout> <Button android:id="@+id/mybut1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAllCaps="false" android:text="@string/button1"/> <TextView android:id="@+id/mytext1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:text="@string/text"/> </LinearLayout> 我想要讓我的textview1顯示在我的button1的旁邊 可是我這樣弄怎麼只有顯示出button1而已 其他的都沒有出現 有人可以幫我看看嗎? 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.146.85.149 ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1463472962.A.E4A.html ※ 編輯: a43149 (122.146.85.149), 05/17/2016 16:16:24

05/17 16:24, , 1F
要不要先說明哪一個是textview1哪一個是button1?
05/17 16:24, 1F

05/17 17:26, , 2F
你的layout只會出現mybut跟mytext這兩個吧...
05/17 17:26, 2F

05/17 17:28, , 3F
調整一下裡面LinearLayout layout_height試試?
05/17 17:28, 3F

05/17 17:44, , 4F
你採用了 horizontal的linear來包你的textview跟button
05/17 17:44, 4F

05/17 17:45, , 5F
為了要實現"textview1顯示在我的button1的旁邊"
05/17 17:45, 5F

05/17 17:46, , 6F
但是你的mytext的width=match_parent 所以mybut消失了
05/17 17:46, 6F

05/17 17:48, , 7F
解法:使用layout_weight,或者是relative layout
05/17 17:48, 7F
文章代碼(AID): #1NEjD2vA (AndroidDev)