[英]Buttons in layout inflater not all the same size
我正在使用inflate在android中進行活動。 我從數據庫中檢索到的所有信息都是正確的,但是由於某些原因,按鈕的寬度似乎沒有相同的大小,我無法弄清楚為什么? 這是一個布局膨脹器,因此從db獲取的數據越多,具有兩個textview和一個button的按鈕行越多
這是XML代碼
<?xml version="1.0" encoding="utf-8"?>
<TableRow
android:id="@+id/visitorNotLeft"
android:layout_width="match_parent"
android:paddingTop="20dp"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/names"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:paddingLeft="50dp"
android:text="" />
<TextView
android:id="@+id/companies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:text="" />
<Button
android:id="@+id/timeOut"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:layout_weight="1"
android:background="@drawable/appsignout_button"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="" />
</TableRow>
<TableRow
android:id="@+id/visitorNotLeft"
android:layout_width="fill_parent" --you can change this to fill_parent
android:paddingTop="20dp"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/names"
android:layout_width="0dp" --you can change this to 0dp
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:paddingLeft="50dp"
android:text="" />
<TextView
android:id="@+id/companies"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="left"
android:text="" />
<Button
android:id="@+id/timeOut"
android:layout_width="0dp" --you can change this to 0dp
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:layout_weight="1"
android:background="@drawable/appsignout_button"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="" />
</TableRow>
您的寬度為wrap_content
,這意味着它們將拉伸以適合內容。 因此,如果一個Button
包含一長串文本,它將更大。
另外,使用布局權重時,必須根據方向將寬度或高度設置為零。 看看docs中的示例:
<EditText
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="@string/message" />
高度設置為零:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.