Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在线性布局中将左侧图像向右移动_Java_Android_Android Linearlayout_Android Relativelayout - Fatal编程技术网

Java 在线性布局中将左侧图像向右移动

Java 在线性布局中将左侧图像向右移动,java,android,android-linearlayout,android-relativelayout,Java,Android,Android Linearlayout,Android Relativelayout,我想把左边的图像移到右边,但我做不到。 我知道我可以使用Layout\u Direction=“rtl”,但我不想使用它。在某些手机上,布局已损坏 这是我的layout.xml <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout

我想把左边的图像移到右边,但我做不到。 我知道我可以使用
Layout\u Direction=“rtl”
,但我不想使用它。在某些手机上,布局已损坏

这是我的layout.xml

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:minHeight="?attr/actionBarSize"
        android:orientation="horizontal">

        <RelativeLayout
            android:id="@+id/icon_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/spacing_large"
            android:layout_marginTop="@dimen/spacing_middle"
            android:layout_marginRight="@dimen/spacing_large"
            android:orientation="vertical">

            <RelativeLayout
                android:id="@+id/icon_front"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fillAfter="false"
                android:fillEnabled="false">

                <ImageView
                    android:id="@+id/icon_profile"
                    android:layout_width="40dp"
                    android:layout_height="40dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
            </RelativeLayout>

        </RelativeLayout>

        <View
            android:layout_width="@dimen/spacing_medium"
            android:layout_height="0dp" />

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

            <LinearLayout
                android:id="@+id/message_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:orientation="vertical"
                android:paddingTop="@dimen/spacing_middle"
                android:paddingBottom="@dimen/spacing_middle">

                <TextView
                    android:id="@+id/from"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="@dimen/spacing_middle"
                    android:layout_marginRight="@dimen/spacing_middle"
                    android:gravity="right"
                    android:maxLines="1"
                    android:text="People Name"
                    />

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

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/spacing_medium"
                        android:layout_marginEnd="@dimen/spacing_middle"
                        android:layout_marginRight="@dimen/spacing_middle"
                        android:gravity="right"
                        android:maxLines="1"
                        android:text="some new text for new items"
android:textAppearance="@style/TextAppearance.AppCompat.Small"/>
                </LinearLayout>
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/grey_10" />

        </LinearLayout>

    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>


那么我怎样才能把图像放在右边呢?此外,重力不起作用我尝试使用重力,但没有将图像向右移动

图像视图位于一个
相对视图
内,因此您需要添加此属性:

android:layout_alignParentEnd="true"
或者,如果您不需要RTL支持:

android:layout_alignParentRight="true"
xml将是:

<ImageView
    android:id="@+id/icon_profile"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentEnd="true"/>

图像视图位于
RelativeLayout
内,因此您需要添加此atribute:

android:layout_alignParentEnd="true"
或者,如果您不需要RTL支持:

android:layout_alignParentRight="true"
xml将是:

<ImageView
    android:id="@+id/icon_profile"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignParentEnd="true"/>