2012-07-16 40 views
0

对于一个介绍页面,为一个Android应用程序,我想使9个按键顺序如下:九个图像由3 Android的布局

[img1][img2][img3] 
[img4][img5][img6] 
[img7][img8][img9] 

有每个图像(10dp)之间的空白

问题是,当我使用LinearLayouts时,总会有一个空白区域。相同的表。 我无法使用GridLayout,因为该应用需要支持Android 2.2

我希望你能帮助我!

P.S. 下面是代码

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:id="@+id/tl" 
       android:layout_width="220dp" 
       android:layout_height="220dp" 
       android:src="@drawable/home_tl" /> 

      <ImageView 
       android:id="@+id/ImageView05" 
       android:layout_width="220dp" 
       android:layout_height="220dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:src="@drawable/home_tc" /> 

      <ImageView 
       android:id="@+id/ImageView06" 
       android:layout_width="220dp" 
       android:layout_height="220dp" 
       android:src="@drawable/home_tr" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:id="@+id/ImageView01" 
       android:layout_width="220dp" 
       android:layout_height="220dp" 
       android:src="@drawable/home_ml" /> 

      <ImageView 
       android:id="@+id/ImageView02" 
       android:layout_width="220dp" 
       android:layout_height="220dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:src="@drawable/home_mc" /> 

      <ImageView 
       android:id="@+id/ImageView03" 
       android:layout_width="220dp" 
       android:layout_height="220dp" 
       android:src="@drawable/home_mr" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="220dp" 
       android:layout_height="220dp" 
       android:src="@drawable/home_bl" /> 

      <ImageView 
       android:id="@+id/imageView2" 
       android:layout_width="220dp" 
       android:layout_height="220dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:src="@drawable/home_bc" /> 

      <ImageView 
       android:id="@+id/imageView3" 
       android:layout_width="220dp" 
       android:layout_height="220dp" 
       android:src="@drawable/home_br" /> 
     </LinearLayout> 
    </LinearLayout> 

的例子的问题是,图像不适合在屏幕上。它必须适合于各种规模(甚至是平板电脑10.1)

解决: 我增加了对每一个ImageView的android:adjustViewBounds="true"和使用layout_weight="1"

+1

u能张贴xml文件? – AkashG 2012-07-16 12:31:14

+0

我不清楚。你想摆脱空白? – darsh 2012-07-16 12:32:07

+0

我添加了额外的信息 – 2012-07-16 12:36:02

回答

1

尝试使用水平方向的LinearLayout,并在里面,取3个ImageButtons并保持每个的宽度fill_parent和weight = 1,这将给所有3 imageButton等宽。

为如

<LinearLayout 
android:orientaion="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
> 

    <LinearLayout 
    android:orientaion="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
    <ImageButton 
    android:layout_width="fill_parent" 
    android:weight="1" 
    android:layout_height="wrap_content" 
    /> 
    <ImageButton 
    android:layout_width="fill_parent" 
    android:weight="1" 
    android:layout_height="wrap_content" 
    /> 
    <ImageButton 
    android:layout_width="fill_parent" 
    android:weight="1" 
    android:layout_height="wrap_content" 
    /> 
</LinearLayout> 

<LinearLayout 
    android:orientaion="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
     <ImageButton 
     android:layout_width="fill_parent" 
     android:weight="1" 
     android:layout_height="wrap_content" 
     /> 
     <ImageButton 
     android:layout_width="fill_parent" 
     android:weight="1" 
     android:layout_height="wrap_content" 
     /> 
     <ImageButton 
     android:layout_width="fill_parent" 
     android:weight="1" 
     android:layout_height="wrap_content" 
     /> 
    </LinearLayout> 

    <LinearLayout 
    android:orientaion="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
     <ImageButton 
     android:layout_width="fill_parent" 
     android:weight="1" 
     android:layout_height="wrap_content" 
     /> 
     <ImageButton 
     android:layout_width="fill_parent" 
     android:weight="1" 
     android:layout_height="wrap_content" 
     /> 
     <ImageButton 
     android:layout_width="fill_parent" 
     android:weight="1" 
     android:layout_height="wrap_content" 
     /> 
    </LinearLayout> 
<LinearLayout> 
+0

这就是我第一次尝试的方式,但是imageview的高度会出现问题。我上传了一张图片http://imageshack.us/photo/my-images/713/naamloosmp.png/ '' – 2012-07-16 12:51:46

+0

不要去android:layout_width =“wrap_content”..改为去android:layout_width = “fill_parent”,每当你使用weight = 1..And为高度,你有像minHeight和maxHeight属性...你可以使用它来预先定义什么应该是你的最小高度和最大高度,当设备是不同的.. – 2012-07-16 12:56:56

+0

I已经解决了这个问题。感谢你和钻石。谢谢! – 2012-07-16 12:57:42

1

我认为你需要把它添加到ImageView

android:adjustViewBounds="true" 
+0

我已经解决了这个问题。感谢你和Androider。谢谢! – 2012-07-16 12:57:56