gpt4 book ai didi

java - CardView 列表不在我的应用程序中滚动

转载 作者:行者123 更新时间:2023-12-01 18:02:01 24 4
gpt4 key购买 nike

我使用小部件 CardView 创建了一个布局。它显示卡片 View 列表,但不向下滚动,请参阅下面的布局。我还创建了AppWall.java。确实需要向 java 类或布局添加任何内容才能使其工作。

<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context="net.example.app.AppWall">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ddd"
android:orientation="vertical"
android:padding="16dp">


<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:minHeight="55dp"
android:id="@+id/topspace">
</Space>



<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">



<ImageView
android:id="@+id/cardview_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image"
android:paddingBottom="5dp"
android:text="Flipkart App"
android:textSize="24sp" />

<TextView
android:id="@+id/tvInstall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title"
android:layout_toRightOf="@+id/cardview_image"
android:text="Install"
android:textColor="@android:color/holo_green_dark"
android:textSize="16sp" />

</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">

<ImageView
android:id="@+id/cardview_image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image1"
android:paddingBottom="5dp"
android:text="Viral Android"
android:textSize="24sp" />

<TextView
android:id="@+id/short_description1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title1"
android:layout_toRightOf="@+id/cardview_image1"
android:text="Free android tutorials and examples for beginners and expert."
android:textColor="#8b8b8b" />

</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">

<ImageView
android:id="@+id/cardview_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image2"
android:paddingBottom="5dp"
android:text="Viral Android"
android:textSize="24sp" />

<TextView
android:id="@+id/short_description2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title2"
android:layout_toRightOf="@+id/cardview_image2"
android:text="Free android tutorials and examples for beginners and expert."
android:textColor="#8b8b8b" />

</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">

<ImageView
android:id="@+id/cardview_image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image3"
android:paddingBottom="5dp"
android:text="Viral Android"
android:textSize="24sp" />

<TextView
android:id="@+id/short_description3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title3"
android:layout_toRightOf="@+id/cardview_image3"
android:text="Free android tutorials and examples for beginners and expert."
android:textColor="#8b8b8b" />

</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">

<ImageView
android:id="@+id/cardview_image4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image4"
android:paddingBottom="5dp"
android:text="Viral Android"
android:textSize="24sp" />

<TextView
android:id="@+id/short_description4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title4"
android:layout_toRightOf="@+id/cardview_image4"
android:text="Free android tutorials and examples for beginners and expert."
android:textColor="#8b8b8b" />

</RelativeLayout>

</android.support.v7.widget.CardView>

</LinearLayout>

<include layout="@layout/toolbar" />

</RelativeLayout>

最佳答案

使用ScrollView在RelativeLayout之后和线性布局之前。 CardView 是简单的 View ,不包含可滚动功能。

<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context="net.example.app.AppWall">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ddd"
android:orientation="vertical"
android:padding="16dp">


<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:minHeight="55dp"
android:id="@+id/topspace">
</Space>



<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">



<ImageView
android:id="@+id/cardview_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image"
android:paddingBottom="5dp"
android:text="Flipkart App"
android:textSize="24sp" />

<TextView
android:id="@+id/tvInstall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title"
android:layout_toRightOf="@+id/cardview_image"
android:text="Install"
android:textColor="@android:color/holo_green_dark"
android:textSize="16sp" />

</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">

<ImageView
android:id="@+id/cardview_image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image1"
android:paddingBottom="5dp"
android:text="Viral Android"
android:textSize="24sp" />

<TextView
android:id="@+id/short_description1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title1"
android:layout_toRightOf="@+id/cardview_image1"
android:text="Free android tutorials and examples for beginners and expert."
android:textColor="#8b8b8b" />

</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">

<ImageView
android:id="@+id/cardview_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image2"
android:paddingBottom="5dp"
android:text="Viral Android"
android:textSize="24sp" />

<TextView
android:id="@+id/short_description2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title2"
android:layout_toRightOf="@+id/cardview_image2"
android:text="Free android tutorials and examples for beginners and expert."
android:textColor="#8b8b8b" />

</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">

<ImageView
android:id="@+id/cardview_image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image3"
android:paddingBottom="5dp"
android:text="Viral Android"
android:textSize="24sp" />

<TextView
android:id="@+id/short_description3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title3"
android:layout_toRightOf="@+id/cardview_image3"
android:text="Free android tutorials and examples for beginners and expert."
android:textColor="#8b8b8b" />

</RelativeLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:id="@+id/android_card_view_example4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:elevation="4dp"
android:padding="16dp">

<ImageView
android:id="@+id/cardview_image4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="18dp"
android:src="@drawable/profile" />

<TextView
android:id="@+id/cardview_list_title4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/cardview_image4"
android:paddingBottom="5dp"
android:text="Viral Android"
android:textSize="24sp" />

<TextView
android:id="@+id/short_description4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cardview_list_title4"
android:layout_toRightOf="@+id/cardview_image4"
android:text="Free android tutorials and examples for beginners and expert."
android:textColor="#8b8b8b" />

</RelativeLayout>

</android.support.v7.widget.CardView>

</LinearLayout>
</ScrollView>

<include layout="@layout/toolbar" />

</RelativeLayout>

您可以做的其他事情是使用 RecyclerView显示卡片列表。

关于java - CardView 列表不在我的应用程序中滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40200088/

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