2017-06-13 71 views
1

我想在線性佈局中將右側的2個圖像對齊。如何在2個圖像之間添加空間? 這是我的代碼。將線性佈局中的2個圖像對齊

Vechile.xml

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 
    <Image 
    android:id="@+id/image1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/img1" 
    android:layout_marginEnd="20dp" /> 

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

    <View 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_weight="1" />     

    <Image 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginEnd="10dp" 
    android:src="@drawable/img2" 
    android:id="@+id/image2"/> 

</LinearLayout> 
</LinearLayout> 

回答

0

設置你的LinearLayout重力權,並採取一定的餘量在ImageViews這樣的:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:gravity="right"> 

<ImageView 
    android:id="@+id/image1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="5dp" 
    android:background="@drawable/arrow_down_black_24dp" 
    /> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/image2" 
    android:layout_margin="5dp" 
    android:background="@drawable/arrow_down_black_24dp" 
    /> 

</LinearLayout> 
相關問題