Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.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 RecyclerView宽度比屏幕宽_Android_Android Recyclerview_Constraints_Width - Fatal编程技术网

Android RecyclerView宽度比屏幕宽

Android RecyclerView宽度比屏幕宽,android,android-recyclerview,constraints,width,Android,Android Recyclerview,Constraints,Width,我正在用CardView设置一个回收视图。然而,尽管有各种限制,CardView仍延伸到屏幕的右侧 这是我的密码: //////////////////////////////////////////////////////// 适配器: ////////////////////////////////////////////////////// RecyclerView项的XML <?xml version="1.0" encoding="utf-8&quo

我正在用CardView设置一个回收视图。然而,尽管有各种限制,CardView仍延伸到屏幕的右侧

这是我的密码:

//////////////////////////////////////////////////////// 适配器:

////////////////////////////////////////////////////// RecyclerView项的XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/secondaryGray"
    android:orientation="vertical"
    android:padding="10dp">

    <androidx.cardview.widget.CardView

        android:id="@+id/corner"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginBottom="10dp"
        app:cardCornerRadius="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:text="TextView"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>

        />

    </androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

/>
///////////////////////////////////////////////////// 用于RecyclerView片段的XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/secondaryGray"
    android:layout_alignParentRight="true"
    tools:context=".ExpertsFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/experts_recycler_view"

        android:layout_width="0dp"
        android:layout_height="0dp"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

试试这个简单的删除约束

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

   


    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rv_xxx"/>


</LinearLayout>

我不确定这一点,但你也可以尝试下面的代码

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="10dp">

<androidx.cardview.widget.CardView

    android:id="@+id/corner"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="10dp"
    android:layout_marginBottom="10dp"
    app:cardCornerRadius="20dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="TextView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    />

</androidx.cardview.widget.CardView>

/>

试试这个简单的删除约束

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

   


    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rv_xxx"/>


</LinearLayout>

我不确定这一点,但你也可以尝试下面的代码

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="10dp">

<androidx.cardview.widget.CardView

    android:id="@+id/corner"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginEnd="10dp"
    android:layout_marginBottom="10dp"
    app:cardCornerRadius="20dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:text="TextView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    />

</androidx.cardview.widget.CardView>

/>

我想出来了。我错误地改变了底部导航栏上方碎片的宽度。

我找到了答案。我错误地更改了底部导航栏上方片段的宽度。

android:layout\u alignParentRight=“true”,从约束布局中删除此项^XML for RecyclerView Fragment codecan您可以检查我的答案i update RecyclerView Item class您可以进行检查我不确定,但我认为可能存在其他代码看起来正常的问题。android:layout\u alignParentRight=“true”,从约束布局^XML for RecyclerView Fragment codecan中删除此项您可以检查我的答案我更新RecyclerView Item类您可以检查此项我不确定,但我认为问题可能存在其他代码看起来正常。我尝试了。还是一样的结果。我认为这是一个运行时问题,因为它在XML预览中正确显示。可能是因为它是一个碎片。但无论如何,谢谢你的支持,我试过了。还是一样的结果。我认为这是一个运行时问题,因为它在XML预览中正确显示。可能是因为它是一个碎片。但无论如何,谢谢你的支持。