Android 安卓布局我想看到一个文本和下面这个文本图像,填补所有的空白

Android 安卓布局我想看到一个文本和下面这个文本图像,填补所有的空白,android,Android,您不应该像那样使用嵌套的线性/相对Layout 无论如何,试着在图片周围涂上相对的颜色,比如上面的或是toleftof等 编辑:我没有看到您的主要布局是线性的,那么您必须在每个内部布局上使用权重=1,这样它们就不会优先于彼此。但是对一个元素使用相对布局只会让你的应用程序变慢--- 将图像视图的支架更改为线性布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_

您不应该像那样使用嵌套的线性/相对Layout

无论如何,试着在图片周围涂上相对的颜色,比如上面的或是toleftof等

编辑:我没有看到您的主要布局是线性的,那么您必须在每个内部布局上使用权重=1,这样它们就不会优先于彼此。但是对一个元素使用相对布局只会让你的应用程序变慢---


图像视图的支架更改为
线性布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="vertical"
android:paddingRight="?android:attr/scrollbarSize" >

<RelativeLayout
android:id="@+id/rl_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
 >

<TextView
    android:id="@+android:id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:singleLine="true"
    android:text="222"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+android:id/summary"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@android:id/title"
    android:layout_below="@android:id/title"
    android:maxLines="4"
    android:text="222ssss"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="?android:attr/textColorSecondary" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/rl_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"

android:layout_below="@id/rl_1" >

<TextView
    android:id="@+android:id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:singleLine="true"
    android:text="222"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+android:id/summary"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@android:id/title"
    android:layout_below="@android:id/title"
    android:maxLines="4"
    android:text="222ssss"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="?android:attr/textColorSecondary" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
android:layout_below="@id/rl_2">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/button_background_dark_default"
        android:contentDescription="@string/image"
        android:scaleType="fitXY" />
</RelativeLayout>

</RelativeLayout>


您的
RelativeLayout
正在扩展,因为它的
匹配父项内容。

这就是您要找的吗?根据我的说法,您的布局可以通过使用
android:orientation=“vertical”



这里的技巧是这些属性
android:layout\u height=“0dp”
android:layout\u weight=“1”
。它会告诉android,你想让你的图像填满所有的空白。

我想这应该行得通,但如果你能用嵌套的相对布局来解决他的问题……嵌套布局是你应该尽量避免的事情,因为它们会大大降低应用程序的速度。这是因为Android构建了一个页面内容树,而布局迫使他在第一棵树的内部构建第二棵树。例如,内部只有一个元素的相对布局可以很容易地删除。在你的另一张照片中,你似乎只使用了bellow,这是你的直线布局可以处理的事情。在编辑之后,将这些视图删除会使应用程序更快:将其他视图放在一边填充空白的最简单方法是将权重设置为1。它并不比其他视图占优势,但填补了我尝试的剩余空间,但都是一样的。图像没有覆盖整个屏幕。我不清楚你想要什么。如果它覆盖整个屏幕,您将无法看到任何其他视图。这是你想要的吗?“课文后”是什么意思?不能同时有“之后”和“结束”?我想看到文本和文本图像下的文本。对不起,这是什么意思?“图像未覆盖整个屏幕”?如果它覆盖整个屏幕,您将看不到文本。请详细说明。你仍在为他提供嵌套布局的解决方案,这确实不完美。如果你想看到视图重叠,请使用框架布局而不是相对布局。我认为他不想要重叠视图。嗯,我不知道他到底想要什么,不是很清楚,他把它修好了!先生,你应该得到一个公正的回答。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="vertical"
android:paddingRight="?android:attr/scrollbarSize" >

<RelativeLayout
android:id="@+id/rl_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
 >

<TextView
    android:id="@+android:id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:singleLine="true"
    android:text="222"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+android:id/summary"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@android:id/title"
    android:layout_below="@android:id/title"
    android:maxLines="4"
    android:text="222ssss"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="?android:attr/textColorSecondary" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/rl_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dip"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"

android:layout_below="@id/rl_1" >

<TextView
    android:id="@+android:id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:singleLine="true"
    android:text="222"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+android:id/summary"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@android:id/title"
    android:layout_below="@android:id/title"
    android:maxLines="4"
    android:text="222ssss"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="?android:attr/textColorSecondary" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
android:layout_below="@id/rl_2">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/button_background_dark_default"
        android:contentDescription="@string/image"
        android:scaleType="fitXY" />
</RelativeLayout>

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

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/button_background_dark_default"
        android:contentDescription="@string/image"
        android:scaleType="fitXY" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:minHeight="?android:attr/listPreferredItemHeight"
            android:orientation="vertical"
            android:paddingRight="?android:attr/scrollbarSize">

<TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:singleLine="true"
        android:text="222"
        android:textAppearance="?android:attr/textAppearanceLarge"/>

<TextView
        android:id="@+id/summary1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLines="4"
        android:text="222ssss"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="?android:attr/textColorSecondary"/>


<TextView
        android:id="@+id/title2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:fadingEdge="horizontal"
        android:singleLine="true"
        android:text="222"
        android:textAppearance="?android:attr/textAppearanceLarge"/>

<TextView
        android:id="@+id/summary2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLines="4"
        android:text="222ssss"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="?android:attr/textColorSecondary"/>

<ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/button_background_dark_default"
        android:scaleType="fitXY"/>

</LinearLayout>