2012-07-16 60 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