如何使具有不同長度標題的 3 個垂直購買按鈕的寬度都相同。標題可以更改。目前我把它們放在一個約束布局中,但你可以看到寬度是不同的。我懷疑這很容易,因為所有問題都涉及水平按鈕。

uj5u.com熱心網友回復:
我個人會通過添加一個方向設定為“垂直”的線性布局來解決這個問題。
- 創建一個線性布局并設定約束。
- 設定寬度和高度以包裹內容(這意味著寬度將與最長的孩子一樣長)。
- 在線性布局內添加 3 個按鈕。
- 確保將每個按鈕的寬度設定為“匹配父級”。這會將按鈕的寬度設定為父線性布局的寬度。
檢查此示例 xml 代碼:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/textView2">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0.49$ / Month"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="4.99$ / Year"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="14.99$ / Forever"/>
</LinearLayout>
希望我的回答對你有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/442390.html
下一篇:特定父標簽下的XML決議
