我有兩個不同的LinearLayout(垂直)。 1st LinearLayout有3個按鈕,分別命名爲btnX,btnY,btnZ。第二個LinearLayout有兩個名爲btnA,btnB的按鈕。 btnB頂端對齊應該遵循btnY。如果我添加一個新的按鈕btnX(假設),btnB的高度將會隨着圖片的增加而增加。你可以從中得到一個清晰的想法。如何在不同的linearLayout上使用另一個按鈕匹配按鈕高度?
0
A
回答
0
你可以使用佈局權重。 在你LinearLayouts,添加 android:weightSum=3
然後,分配這每個佈局: android:layout_weight=1
這樣一來,任何按鈕將肩負起高度的1/3,不管你有多少佈局都有。如果你想有一個按鈕拍攝高度的2/3,layout_weight設置爲2
0
最有效的解決方案是實現一個相對佈局...但你可以嘗試把你的按鈕B內的另一個獨立的LinearLayout,並把他們的RelativeLayout
0
內對此進行詳細說明,但我希望它能幫助。變化的寬度和高度,只要你喜歡,按鈕B的高度爲((按鈕A的高度)* 2)+按鈕
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnZ"
android:layout_width="216dp"
android:layout_height="86dp"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Button Z"/>
<Button
android:id="@+id/btnY"
android:layout_width="216dp"
android:layout_height="86dp"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Button Y"
android:layout_below="@+id/btnZ"/>
<Button
android:id="@+id/btnX"
android:layout_width="216dp"
android:layout_height="86dp"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Button X"
android:layout_below="@+id/btnY"/>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnA"
android:layout_width="216dp"
android:layout_height="86dp"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Button A"/>
<Button
android:id="@+id/btnB"
android:layout_width="216dp"
android:layout_height="196dp"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="Button B"
android:layout_below="@+id/btnA"/>
相關問題
- 1. 高度不匹配 - 按鈕
- 2. 如何獲得按鈕的高度以匹配另一個元素的高度?
- 3. 得到不同的按鈕高度爲同一個按鈕
- 4. 銷燬LinearLayout中一個按鈕的另一個按鈕
- 5. 如何在Android的LinearLayout中設置幾個按鈕的高度?
- 6. 如何構建定位在另一個按鈕上的按鈕?
- 7. 如何在按下另一個按鈕時不斷旋轉按鈕45度?
- 8. 如何在同一高度上貼上按鈕引導程序
- 9. 如何使一個按鈕在不同的視圖控制器上更改另一個按鈕的標題
- 10. 如何點擊另一個按鈕上方的按鈕?
- 11. 如何將按鈕置於頂部的另一個按鈕上
- 12. Chrome上的按鈕高度
- 13. 將Android按鈕設置爲另一個按鈕的高度的一半
- 14. 如何使用單選按鈕來更改另一個按鈕?
- 15. 如何使用另一個按鈕創建按鈕
- 16. 按鈕高度
- 17. 當我按下另一個按鈕時,如何禁用按鈕
- 18. 如何更改UIpickerView上的元素按下按鈕或按另一個按鈕
- 19. 如何使一個按鈕點擊不同頁面上的按鈕
- 20. ?按鈕功能的另一個按鈕
- 21. 如何在android中的另一個按鈕上啓用基於onclick的按鈕?
- 22. 使用另一個按鈕,而不是後退按鈕
- 23. 如何禁用按鈕的另一個按鈕被點擊
- 24. 如何更改按鈕高度而不影響其他按鈕?
- 25. 按鈕覆蓋/衝突在同一網頁上的另一個按鈕
- 26. Android的LinearLayout使按鈕不起作用
- 27. 使用LinearLayout的四個按鈕菜單
- 28. 約束佈局:按鈕的高度不匹配預覽
- 29. 如何添加一個buttton2,同時點擊另一個按鈕1和按鈕3,同時點擊按鈕2
- 30. iphone:在一個按鈕,點擊按鈕的標題應在另一個按鈕
顯示您的佈局代碼的餘量頂部,你已經嘗試到目前爲止 –
我把他們都在一個相對佈局不線性佈局,所以我可以通過一個補充,作爲一項規則,並在同一時間減少我的佈局深度(因而透支)。 –
如果LinearLayout沒有達到您想要的效果,請考慮使用不同的佈局。 RelativeLayout可能正是你需要的。 –