如何在 LinearLayout 中将视图移动到末尾

Wik*_*tor 3 android

我不知道如何将我ImageView的向右移动,现在看起来像这样

在此处输入图片说明

我想要这样的东西,所以图像会粘在右边 CardView

在此处输入图片说明

<android.support.v7.widget.CardView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    app:cardCornerRadius="6dp"
    app:cardElevation="6dp"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        >

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test"/>

        </LinearLayout>

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="50dp"
            android:layout_height="50dp"
            app:srcCompat="@mipmap/ic_launcher" />


    </LinearLayout>

</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

for*_*pas 5

您将获得所需的结果RelativeLayout

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_toStartOf="@id/imageView3">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Test"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Test"/>

    </LinearLayout>

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentEnd="true"
        app:srcCompat="@mipmap/ic_launcher" />


</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

RelativeLayout专为这些情况而设计。如您所见,它只需要一个属性layout_alignParentEnd即可实现您想要的