Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.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
Android布局文本位于左侧,图像位于右侧_Android_Xml_Android Relativelayout_Android Imageview - Fatal编程技术网

Android布局文本位于左侧,图像位于右侧

Android布局文本位于左侧,图像位于右侧,android,xml,android-relativelayout,android-imageview,Android,Xml,Android Relativelayout,Android Imageview,我试图做一个列表,其中图像一直停留在布局的右侧。同时,如果没有图像,我会喜欢主题文本来填充整个布局 这就是我希望实现的 当图像被隐藏时 带图像 电流输出: 文本前面的图像。 试试这个……干杯:) 试试这个……干杯:) 您应该这样做: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" andro

我试图做一个列表,其中图像一直停留在布局的右侧。同时,如果没有图像,我会喜欢主题文本来填充整个布局

这就是我希望实现的
当图像被隐藏时

带图像

电流输出:
文本前面的图像。


试试这个……干杯:)


试试这个……干杯:)



您应该这样做:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/mark_ok" />

    <LinearLayout
        android:id="@+id/leftblock"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/subject"
        android:layout_alignTop="@+id/subject"
        android:layout_toLeftOf="@+id/icon"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/subject"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange" />

        <TextView
            android:id="@+id/cdate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date"
            android:textColor="#8000FF" />
    </LinearLayout>

</RelativeLayout>

您应该这样做:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/mark_ok" />

    <LinearLayout
        android:id="@+id/leftblock"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/subject"
        android:layout_alignTop="@+id/subject"
        android:layout_toLeftOf="@+id/icon"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/subject"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange" />

        <TextView
            android:id="@+id/cdate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date"
            android:textColor="#8000FF" />
    </LinearLayout>

</RelativeLayout>


更有效的方法是使用具有复合绘图功能的textview。更有效的方法是使用具有复合绘图功能的textview。您能说明“应该”的原因吗?Cleaner?在包含2个块的相对布局中,如果指定:layout_toLeftOf=“”“@+”非常重要,因为它指的是一个尚未创建的视图:)您能说明“应该”的原因吗?Cleaner?在包含2个块的相对布局中,如果指定:layout_toLeftOf=“”“@+”非常重要,因为它指的是尚未创建的视图:)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@drawable/mark_ok" />

    <LinearLayout
        android:id="@+id/leftblock"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/subject"
        android:layout_alignTop="@+id/subject"
        android:layout_toLeftOf="@+id/icon"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/subject"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange" />

        <TextView
            android:id="@+id/cdate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date"
            android:textColor="#8000FF" />
    </LinearLayout>

</RelativeLayout>