簡體   English   中英

Android Studio 3 垂直按鈕相同寬度

[英]Android Studio 3 Vertical Buttons Same Width

如何使標題長度不同的 3 個垂直購買按鈕的寬度都相同。 標題可以更改。 目前我將它們放在 constraintlayout 中,但如您所見,寬度不同。 我懷疑這很容易,因為所有問題都涉及水平按鈕。

在此處輸入圖像描述

我個人會通過添加一個方向設置為“垂直”的線性布局來解決這個問題。

  1. 創建線性布局並設置約束。
  2. 設置寬度和高度以包裹內容(這意味着寬度將與最長的孩子一樣長)。
  3. 在線性布局中添加 3 個按鈕。
  4. 確保將每個按鈕的寬度設置為“匹配父項”。 這會將按鈕的寬度設置為父線性布局的寬度。

檢查此示例 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>

希望我的回答對你有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM