Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.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 listview中的相对布局混乱 问题描述_Android_Android Layout_Listview_Android Relativelayout - Fatal编程技术网

Android listview中的相对布局混乱 问题描述

Android listview中的相对布局混乱 问题描述,android,android-layout,listview,android-relativelayout,Android,Android Layout,Listview,Android Relativelayout,我使用显示文件夹列表,列表项布局使用自定义布局 在列表项布局中,我使用RelativeLayout作为根容器。 当运行apk时,ListView的布局一开始就可以正常工作,但是当点击一个丢失了子文件夹和文件的文件夹时就会出现问题 子文件夹布局混乱。奇怪的是,并不是所有的子文件夹布局都变得凌乱,只有丢失了文件和子文件夹的子文件夹。 我通过安装了Kitkat操作系统的1280*720像素、hdpi屏幕的Android设备对其进行了测试 凌乱的布局截图 XML代码 在图形布局工具中预览 使用带重

我使用显示文件夹列表,列表项布局使用自定义布局

在列表项布局中,我使用
RelativeLayout
作为根容器。 当运行apk时,
ListView
的布局一开始就可以正常工作,但是当点击一个丢失了子文件夹和文件的文件夹时就会出现问题

子文件夹布局混乱。奇怪的是,并不是所有的子文件夹布局都变得凌乱,只有丢失了文件和子文件夹的子文件夹。 我通过安装了Kitkat操作系统的1280*720像素、hdpi屏幕的Android设备对其进行了测试

凌乱的布局截图

XML代码

在图形布局工具中预览

使用带重量的线性布局,而不是相对长度,这可以根据您的要求轻松完成:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="@color/white"
    android:padding="10dp" >

    <ImageView
        android:id="@+id/list_item_icon"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@drawable/folder" />


    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">
        <TextView
            android:id="@+id/list_item_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:lines="1"
            android:singleLine="true" 
            android:text="list_item_titlelist_item_titlelist_item_titlelist_item_titlelist_item_titlelist_item_title"
            android:textColor="#282828"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/list_item_subtitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#555555" 
            android:text="list_item_titlem_titlelist_item_title"
            android:textSize="12sp" />

    </LinearLayout>


    <ImageView
        android:id="@+id/list_item_action"
        android:layout_width="60dp"
        android:src="@drawable/folder"
        android:layout_height="match_parent" />
</LinearLayout>

试试这个

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="48dp"
    android:background="@color/white"
    android:padding="10dp" >

    <ImageView
        android:id="@+id/list_item_icon"
        android:layout_width="60dp"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/folder" />

    <ImageView
        android:id="@+id/list_item_action"
        android:layout_width="60dp"
        android:layout_height="fill_parent"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/folder" />

    <TextView
        android:id="@+id/list_item_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/list_item_action"
        android:layout_toRightOf="@id/list_item_icon"
        android:gravity="left"
        android:lines="1"
        android:paddingLeft="8dp"
        android:singleLine="true"
        android:text="list_item_titlelist_item_titlelist_item_titlelist_item_titlelist_item_titlelist_item_title"
        android:textColor="#282828"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/list_item_subtitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/list_item_title"
        android:layout_below="@id/list_item_title"
        android:layout_toLeftOf="@+id/list_item_action"
        android:gravity="left"
        android:paddingLeft="8dp"
        android:text="list_item_titlem_titlelist_item_title"
        android:textColor="#555555"
        android:textSize="12sp" />

</RelativeLayout>


您可以在Github上找到主xml。请确保所有图像的图像宽度相同。这不会修复错误。可能是Pullt刷新Listview造成的。我忘了注意到我使用了PullToRefreshListView而不是内置ListView我认为这是您的列表项布局,无论您使用的是哪种ListView类型。但是我复制了您的代码并运行了它,同样的错误也发生了。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="48dp"
    android:background="@color/white"
    android:padding="10dp" >

    <ImageView
        android:id="@+id/list_item_icon"
        android:layout_width="60dp"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/folder" />

    <ImageView
        android:id="@+id/list_item_action"
        android:layout_width="60dp"
        android:layout_height="fill_parent"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/folder" />

    <TextView
        android:id="@+id/list_item_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/list_item_action"
        android:layout_toRightOf="@id/list_item_icon"
        android:gravity="left"
        android:lines="1"
        android:paddingLeft="8dp"
        android:singleLine="true"
        android:text="list_item_titlelist_item_titlelist_item_titlelist_item_titlelist_item_titlelist_item_title"
        android:textColor="#282828"
        android:textSize="14sp" />

    <TextView
        android:id="@+id/list_item_subtitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/list_item_title"
        android:layout_below="@id/list_item_title"
        android:layout_toLeftOf="@+id/list_item_action"
        android:gravity="left"
        android:paddingLeft="8dp"
        android:text="list_item_titlem_titlelist_item_title"
        android:textColor="#555555"
        android:textSize="12sp" />

</RelativeLayout>