Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.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 CardView在添加新项目时更改大小_Android_Android Layout_Android Cardview - Fatal编程技术网

Android CardView在添加新项目时更改大小

Android CardView在添加新项目时更改大小,android,android-layout,android-cardview,Android,Android Layout,Android Cardview,我试图修改从rss链接获取新闻提要的源代码,并以这种线性布局显示它 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_p

我试图修改从rss链接获取新闻提要的源代码,并以这种线性布局显示它

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="10dp"
    android:layout_marginTop="9dp"
    android:layout_marginLeft="9dp"
    android:layout_marginRight="9dp"
    card_view:cardElevation="0.01dp"
    android:layout_marginBottom="0dp"
    card_view:cardPreventCornerOverlap="true"
    card_view:cardUseCompatPadding="true"
    android:id="@+id/cardview">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/date_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_margin="@dimen/activity_horizontal_margin"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <ImageView
            android:id="@+id/thumb_img"
            android:scaleType="centerCrop"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_below="@+id/date_text"
            android:layout_centerHorizontal="true" />

        <TextView
            android:ellipsize="end"
            android:id="@+id/title_text"
            android:adjustViewBounds="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/thumb_img"
            android:layout_centerHorizontal="true"
            android:background="#80000000"
            android:padding="8dp"
            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceLargeInverse" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Description"
            android:textSize="15dp"
            android:padding="10dp"
            android:fontFamily="@font/g_light"
            android:textColor="#000"
            android:id="@+id/description_text"
            android:layout_below="@+id/thumb_img"
            android:layout_alignRight="@+id/date_text"
            android:layout_alignEnd="@+id/date_text" />
    </RelativeLayout>


</androidx.cardview.widget.CardView>
</LinearLayout>
我的问题是,每次添加新源时,我的卡视图都会更改大小:

我的问题输出示例:

你能用包含recyclerview的布局更新你的问题吗?好的,我现在添加它设置recyclerview宽度以匹配父级并测试一次。仍然是相同的问题我解决了问题,问题出现在java代码recyclerview.addItemDecoration(新的垂直空间(20));因此,对于每个新源,都需要添加一个垂直空间。非常感谢您的帮助,您能用由recyclerview组成的布局更新您的问题吗?好的,我现在将添加它设置recyclerview宽度以匹配父级并测试一次。仍然是相同的问题我解决了问题,问题出现在java代码中,recyclerview.addItemDecoration(新的垂直空间(20));因此,对于每个新源,都需要添加一个垂直空间。非常感谢你的帮助
<?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"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimary"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:showIn="@layout/activity_main">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/recyclerview"
            />
    </RelativeLayout>
for (int i = 0; i < sources.length; i++) {
            readRss = new ReadRss( this, recyclerView, sources[i]);
            readRss.execute();
        }
feedItems.add(item);