2013-09-25 17 views
0

我想在屏幕的底部以相同的重量顯示三個ImageViews。但圖像的大小不固定。我想展示2張圖片,其中一張應該隱藏,我該怎麼辦?
如何調整應該彼此並排的三個ImageViews和第三個ImageView之間的空間不應與屏幕上可見的兩個ImageViews重疊?如何在Android中水平對齊三個ImageViews?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/main_imge_1" 
    android:orientation="vertical" > 

    <ImageView 
    android:id="@+id/imageView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 

    android:background="#F9F939" 
    android:src="@drawable/ic_launcher" 
    android:layout_toLeftOf ="@+id/imageView6" 
    android:layout_alignParentBottom="true" 
    android:padding="15dp" /> 

<ImageView 
    android:id="@+id/imageView6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#54F71D" 

    android:src="@drawable/ic_launcher" 
    android:layout_alignParentBottom="true" 
    android:padding="15dp" 
    android:layout_margin="10dp" /> 

    <ImageView 
    android:id="@+id/imageView7" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#1DF7AB" 
    android:src="@drawable/ic_launcher" 
    android:layout_alignParentBottom="true" 
    android:layout_toRightOf="@+id/imageView6" 
    android:padding="15dp" /> 

</RelativeLayout> 
+2

尊敬的用戶,歡迎來到StackOverflow。請大聲朗讀問題的第一行,並告訴我你是否瞭解他們。然後,請向我解釋 - 特別是最後一句。 –

+0

你想說什麼......請寫清楚...... – WISHY

+0

我想在屏幕底部顯示threeimageview horizo​​natlly我該怎麼做? – user2806157

回答

2

嘗試這種方式

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center|bottom" > 

    <ImageView 
     android:id="@+id/imageView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:layout_weight="1" 
     android:background="#F9F939" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/imageView6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:layout_weight="1" 
     android:background="#54F71D" 
     android:src="@drawable/ic_launcher" /> 

    <ImageView 
     android:id="@+id/imageView7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="5dp" 
     android:layout_weight="1" 
     android:background="#1DF7AB" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

輸出

enter image description here

+0

這工作很好 – user2806157

1

從我能夠解密,你可能想實現這一點:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_alignParentBottom="true" 
     android:gravity="center_horizontal"> 


     <ImageView 
    android:id="@+id/imageView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#F9F939" 
    android:src="@drawable/ic_launcher" 
    android:padding="15dp" 
    android:layout_weight="1" 
    /> 

    <ImageView 
    android:id="@+id/imageView6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#F9F939" 
    android:src="@drawable/ic_launcher" 
    android:padding="15dp" 
    android:layout_weight="1" 
    /> 

    <ImageView 
    android:id="@+id/imageView7" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#F9F939" 
    android:src="@drawable/ic_launcher" 
    android:padding="15dp" 
    android:layout_weight="1" 
    /> 


    </LinearLayout> 

</RelativeLayout> 

結果:

enter image description here

的關鍵是使用一個封閉LinearLayout握住你ImageView S和具有LinearLayoutRelativeLayout對準底部。

0

對於每個ImageView使用android:layout_weight =「1」。並將您的RelativeLayout替換爲Linearlayout。