Android 在listview中的自定义适配器中布局\u

Android 在listview中的自定义适配器中布局\u,android,listview,android-adapter,Android,Listview,Android Adapter,我为listview制作了一个自定义adapter,但它不起作用,两个textview在构建时重叠,但在制作xml时起作用,我使用了下面的layout\u 字符串“nguyen quoc bao”和“13530”是重叠的 在xml中: 我的xml代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android

我为
listview
制作了一个自定义
adapter
,但它不起作用,两个
textview
在构建时重叠,但在制作xml时起作用,我使用了下面的
layout\u

字符串“nguyen quoc bao”和“13530”是重叠的
在xml中

我的
xml
代码:

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

    <TextView
        android:id="@+id/textView_stud_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:paddingLeft="8dp"
        android:textSize="18sp"
        android:textStyle="bold"
        android:text="111"/>

    <TextView
        android:id="@+id/textView_stud_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_below="@+id/textView_stud_name"
        android:paddingLeft="8dp"
        android:textSize="12sp"
        android:text="111"/>

    <Button
        android:id="@+id/btn_absence"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dp"
        android:background="@color/red"
        android:text="Absence" />

    <Button
        android:id="@+id/btn_check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/btn_absence"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dp"
        android:background="@color/green"
        android:text="Check" />

</RelativeLayout>

如何解决这个问题?感谢您的回复。

从第二个文本视图中删除属性

如果为true,则此子对象将在其父对象内垂直居中


从第二个文本视图中删除属性

如果为true,则此子对象将在其父对象内垂直居中


按原样粘贴此布局,这种设计为您将来的更改提供了更大的灵活性(提示-尽量使用线性布局,因为相对布局可能会在运行时对其行为进行太多更改)

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

        <LinearLayout
            android:layout_alignParentLeft="true"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_toLeftOf="@+id/llButtons"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/textView_stud_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:paddingLeft="8dp"
                android:text="111"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView_stud_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textView_stud_name"
                android:layout_centerVertical="true"
                android:paddingLeft="8dp"
                android:text="111"
                android:textSize="12sp" />

        </LinearLayout>   

        <LinearLayout
            android:id="@+id/llButtons"
            android:layout_alignParentRight="true"
            android:layout_width="wrap_content"
            android:orientation="horizontal"
            android:layout_height="wrap_content">
            <Button
                android:id="@+id/btn_absence"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:textColor="@color/black"
                android:layout_marginRight="5dp"
                android:background="@color/red"
                android:text="Absence" />

            <Button
                android:id="@+id/btn_check"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginRight="5dp"
                android:layout_toLeftOf="@id/btn_absence"
                android:background="@color/green"
                android:text="Check" />

        </LinearLayout>


    </RelativeLayout>

按原样粘贴此布局,这种设计为您将来的更改提供了更大的灵活性(提示-尽量使用线性布局,因为相对布局可能会在运行时对其行为进行太多更改)

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

        <LinearLayout
            android:layout_alignParentLeft="true"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_toLeftOf="@+id/llButtons"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/textView_stud_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:paddingLeft="8dp"
                android:text="111"
                android:textSize="18sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView_stud_id"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textView_stud_name"
                android:layout_centerVertical="true"
                android:paddingLeft="8dp"
                android:text="111"
                android:textSize="12sp" />

        </LinearLayout>   

        <LinearLayout
            android:id="@+id/llButtons"
            android:layout_alignParentRight="true"
            android:layout_width="wrap_content"
            android:orientation="horizontal"
            android:layout_height="wrap_content">
            <Button
                android:id="@+id/btn_absence"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:textColor="@color/black"
                android:layout_marginRight="5dp"
                android:background="@color/red"
                android:text="Absence" />

            <Button
                android:id="@+id/btn_check"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginRight="5dp"
                android:layout_toLeftOf="@id/btn_absence"
                android:background="@color/green"
                android:text="Check" />

        </LinearLayout>


    </RelativeLayout>


它移到了下方,但仍然重叠,我认为这是因为页边空白/padding@Ho为了更好的方式,使用LinearLayout&add
android:layou-weight
@Hoángăng,如果您将面临问题,请告诉我。它移到下面,但仍然重叠,我认为是因为空白/padding@Ho为了更好的方式,使用LinearLayout&add
android:layout_weight
@Hoángėng如果您将面临问题,请让我通知您。谢谢您的帮助,但如果我想继续我的第一种方法,如何解决它?您必须保持太多的视图关系….如此视图左侧的视图,此视图右侧的视图,在此下方,上面这张…这张图的左边,这张图的右边,这张图的下面,这张图的上面…这张图的右边,这张图的下面,这张图的上面…那张图的左边,这张图的右边,这张图的下面,这张图的上面…这张图的右边,这张图的下面,这张图的上面…这张图的右边,这张图的右边,这张图的上面…这张图的右边,这张图的右边