gpt4 book ai didi

Android Recyclerview 项目 Textview 不会出现在某些项目中

转载 作者:行者123 更新时间:2023-12-05 00:19:38 25 4
gpt4 key购买 nike

所以在我创建的 Recyclerview 中,我使用 CardView 设置项目布局。这是项目布局:

product_list_item_layout.xml

<com.google.android.material.card.MaterialCardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/CardView"
android:id="@+id/sampleProductCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="12dp"
app:cardCornerRadius="12dp"
app:cardElevation="6dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="8dp"
>

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher_background"
/>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="Apple Pie"
android:textColor="#6f6f6f"
android:textSize="14sp"
android:id="@+id/productName"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="Rp. "
android:textColor="#6f6f6f"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginLeft="2dp"
android:text="Price"
android:textColor="#6f6f6f"
android:textSize="12sp"
android:id="@+id/productPrice"/>

</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="Stock :"
android:textColor="#000"
android:textSize="10sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginLeft="6dp"
android:text="4"
android:textColor="#000"
android:textSize="10sp"
android:id="@+id/productStockQuantity"
/>
</LinearLayout>

</LinearLayout>
</LinearLayout>

</com.google.android.material.card.MaterialCardView>

在 Android Studio 中,设计预览显示为 this .

这是recyclerview布局:

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

tools:context=".mainFragments.ProductListFragment">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>

...

...


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvProductList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
/>

...

</LinearLayout>

</layout>

在 fragment 中,我将其设置为 GridLayout。但它显示为 this .

有关详细信息,请查看 product_list_item.xml 中的 textview与 android:id="@+id/productName"自从我从 API 端点获取数据以来,长度有很多变化。

我认为 fragment 或 recyclerview 适配器没有任何问题。

我在这里错过了什么吗?如果我错过了任何细节,请在评论中提及。

最佳答案

请尝试更改 ImageView 的高度至wrap_content

    <ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher_background"
/>

关于Android Recyclerview 项目 Textview 不会出现在某些项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62207543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com