列表项布局未将项目显示为全宽

问题描述 投票:0回答:2

我正在尝试制作自定义列表布局,每件事情都很好(自定义类和列表适配器)........但是活动上的项目不知何故不会扩展到全屏。这是我的布局设计:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:clickable="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout

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


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

            <TextView
                android:id="@+id/chapter_number"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Name" />

            <TextView
                android:id="@+id/chapter_description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />



        </LinearLayout>


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

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
               android:src="@drawable/ic_arrow_right" />


        </LinearLayout>

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

这是它的样子:

Output

我试图将箭头移动到屏幕的右上角。有什么建议?谢谢

android xml android-layout
2个回答
2
投票

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true">


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

    <TextView
        android:id="@+id/chapter_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name" />

    <TextView
        android:id="@+id/chapter_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


</LinearLayout>


<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:src="@drawable/ic_arrow_right" />


</RelativeLayout>

2
投票

对于箭头,删除layout_weight并使其宽度为wrap_content。现在,所有剩余的重量都应该用章号+描述来消耗,它应该有效。

© www.soinside.com 2019 - 2024. All rights reserved.