2014-01-23 84 views
0

我在我的android项目中创建了xml布局,但它不适合所有屏幕。 有没有什么办法让它适合所有的屏幕?布局不适合所有屏幕

这里是布局内容:

<TableLayout android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> 
    <TableRow android:id="@+id/tableRow1" android:layout_width="100dp" android:layout_height="100dp"> 
     <ImageButton android:src="@drawable/unlock" android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/imageButton1"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton3"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton4"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton6"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton7"></ImageButton> 
    </TableRow> 
    <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content"> 
     <ImageButton android:layout_width="wrap_content" android:id="@+id/imageButton2" android:src="@drawable/lockicon" android:layout_height="wrap_content"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton5"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton8"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton9"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton10"></ImageButton> 
    </TableRow> 
    <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content"> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton11"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton12"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton13"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton14"></ImageButton> 
     <ImageButton android:src="@drawable/lockicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageButton15"></ImageButton> 
    </TableRow> 
</TableLayout> 
+0

使用的LinearLayout与layout_weight属性 – Houcine

回答

0

尝试将所有行的宽度设置为TableRowmatch_parent。同时为所有ImageButton组件添加权重。

0

在你TableLayout使用android:layout_weightSum然后在3个孩子中,指定你想要的权重。

问题是,你的第一个孩子有100dp的恒定测量。所以这不适用于所有屏幕尺寸,因为它们正在改变,而您的测量规格则不是。

+0

weightSum是可选 –

+0

@Tobor是的,但它更容易,当你指定一个weightsum使用权。否则属性不存在 – Ogen

+0

默认情况下,weightSum(如果未指定)** IS **指定权重的总和。 –

0
// try this way 
<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="0dp"> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton1"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton3"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton4"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton6"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton7"/> 
    </TableRow> 
    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="0dp"> 
     <ImageButton 
      android:id="@+id/imageButton2" 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton5"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton8"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton9"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton10"/> 
    </TableRow> 
    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="0dp"> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton11"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton12"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton13"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton14"/> 
     <ImageButton 
      android:src="@drawable/ic_launcher" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="match_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY" 
      android:id="@+id/imageButton15"/> 
    </TableRow> 
</TableLayout>