列表项目版式未显示完整宽度的项目

时间:2019-01-14 12:56:28

标签: android xml android-layout

我正在尝试制作自定义列表布局,每件事都可以正常工作(自定义类和列表Adapter)........但是活动上的项目无法以某种方式扩展到全屏。 这是我的版式设计:

<?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

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

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:2)

对于箭头,删除layout_weight并使其宽度wrap_content。现在,所有剩余的权重应该用章号和说明用尽,并且应该可以使用。