Android 相对布局中的文本对齐方式

Android 相对布局中的文本对齐方式,android,layout,Android,Layout,我试图动态地膨胀我的列表视图中的相对布局,但是我无法根据上面的图像视图包装文本内容。请帮我整理一下 我的相对布局代码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable

我试图动态地膨胀我的
列表视图
中的相对布局,但是我无法根据上面的
图像视图
包装文本内容。请帮我整理一下

我的相对布局代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background_gradient"
    android:orientation="vertical"
    android:paddingRight="5dp" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/img1" />

    <TextView
        android:id="@+id/title_course"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/imageView1"
        android:layout_below="@+id/imageView1"
        android:background="#08298A"
        android:text="This is my text view in android example"
        android:textColor="#FFFFFF" />

</RelativeLayout>

我的自定义列表视图代码如下:我正在线性布局id My_linear内膨胀相对布局

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

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/margin_small" >

    <TextView
        android:id="@+id/title_curriculum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:paddingLeft="5dp" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="5dp"
        android:contentDescription="@string/app_name"
        android:paddingRight="5dp"
        android:src="@drawable/progress_bar" />
</RelativeLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background_gradient"
    android:layout_margin="@dimen/margin_small" >

    <ImageView
        android:id="@+id/course_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/app_name"
        android:src="@drawable/ic_info_scroller" />

    <HorizontalScrollView
        android:layout_marginLeft="5dp"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:scrollbars="none" >

        <LinearLayout
            android:id="@+id/my_linear"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >
        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout>


TextView
XML中将
false
设置为
android:singleLine
,如下所示

android:singleLine="false"
因此,更新的布局XML将

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background_gradient"
    android:orientation="vertical"
    android:paddingRight="5dp" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/img1" />

    <TextView
        android:id="@+id/title_course"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignRight="@+id/imageView1"
        android:layout_below="@+id/imageView1"
        android:background="#08298A"
        android:singleLine="false"
        android:text="This is my text view in android example"
        android:textColor="#FFFFFF" />
</RelativeLayout>

您可以尝试将文本视图粘贴到它自己的线性布局中




您正在宽度上包装内容,因此父级宽度无关紧要。使用
match\u parent
,它应该可以工作。我还删除了parentBottom和alignRight,不确定它是否有效。

我在
文本视图中尝试了
android:width=“0dp”
,并获得了所需的输出

我试过了,得到了同样的结果。我找不到剩下的文本,所以,问题是
TextView
的全文没有显示,对吗?没错,我希望它换行并出现在下一行。您应该添加一个示例图像来解释输出的外观。我无法让您的答案将文本视图换行为宽度=匹配父对象和高度以换行内容。请提供您设置为背景的所需图像。
<ImageView
    android:id="@+id/img"
    android:layout_width="wrap_content"
    android:src="@android:drawable/gallery_thumb"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/img"
    android:layout_alignLeft="@+id/img"
    android:layout_alignRight="@+id/img"
    android:text="This dummy text here testttttttttt"
    android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/title_course"
android:layout_width="**match_parent**"
android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_below="@+id/imageView1"
android:background="#08298A"
android:text="This is my text view in android example"
android:textColor="#FFFFFF" />