簡體   English   中英

以線性布局對齊2個圖像

[英]Align 2 images right in linear layout

我想在線性布局中將右側的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>

將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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM