2017-09-27 143 views
0

我已經定義了以下的Android佈局...Android的佈局控制表高度和寬度包含

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:p1="http://schemas.android.com/apk/res/android" 
    p1:orientation="vertical" 
    p1:layout_width="match_parent" 
    p1:layout_height="match_parent" 
    p1:minWidth="25px" 
    p1:minHeight="25px"> 
    <TableLayout 
     p1:minWidth="25px" 
     p1:minHeight="25px" 
     p1:layout_width="match_parent" 
     p1:layout_height="match_parent" 
     p1:id="@+id/tableLayout1"> 
     <TableRow 
      p1:layout_weight="1" 
      p1:id="@+id/tableRow1" 
      p1:minWidth="25px" 
      p1:minHeight="25px"> 
      <TextView 
       p1:text="Small Text" 
       p1:textAppearance="?android:attr/textAppearanceSmall" 
       p1:layout_width="match_parent" 
       p1:layout_height="match_parent" 
       p1:layout_column="0" 
       p1:id="@+id/textView1" /> 
     </TableRow> 
     <TableRow 
      p1:layout_weight="1" 
      p1:id="@+id/tableRow2" 
      p1:minWidth="25px" 
      p1:minHeight="25px"> 
     </TableRow> 
     <TableRow 
      p1:layout_weight="1" 
      p1:id="@+id/tableRow3" 
      p1:minWidth="25px" 
      p1:minHeight="25px"> 
      <Button 
       p1:text="Button" 
       p1:layout_column="0" 
       p1:id="@+id/button1" 
       p1:layout_width="match_parent" 
       p1:layout_height="50dp" /> 
     </TableRow> 
    </TableLayout> 
</FrameLayout> 

導致...

enter image description here

這是我需要的它要做...

  1. 行1中的TextView需要100dp的靜態高度。
  2. 第3行中的按鈕需要100dp的靜態高度。
  3. 第2排應占用剩餘的可用垂直空間。
  4. TextView的和按鈕應該佔據整個客戶端寬度(無論設備是一個)

我將如何改變佈局XML來做到這一點?

+0

嘗試TextView的高度與100dp和重力設置爲頂部。按鈕與重力底部和行2匹配父母。所有這些都是垂直定向的一個linearylayout。 – Jimmy

回答

1

我不明白你爲什麼要表和行,所以我給你提供了其他的解決方案,哪個RelativeLayout和根據Android文檔是最好的容器使用。

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:layout_alignParentTop="true" 
     android:id="@+id/textView" 
     android:text="text" 
     android:background="#f0f" /> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:background="#0ff" 
     android:orientation="vertical" 
     android:layout_below="@+id/textView" 
     android:layout_above="@+id/button" 
     android:layout_height="fill_parent"> 

    <!--put whenever you want in here--> 

    </LinearLayout> 
    <Button 
    android:layout_alignParentBottom="true" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:id="@+id/button" 
     android:text="button" 
     android:background="#ff0"/> 
</RelativeLayout> 

enter image description here