【问题标题】:Single ListView inside a CardViewCardView 中的单个 ListView
【发布时间】:2018-03-08 13:05:03
【问题描述】:

我有这样的屏幕要求:

但我不能让它像那样工作。我最终制作了这样的视图:

我正在使用 CardView。列表内容正在动态扩展。

    <?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">

    <android.support.v7.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

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

            <TextView
                android:id="@+id/lblProductName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="19dp"
                android:padding="10dp"
                android:text="Product Name"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/lblProductQuantity"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="19dp"
                android:padding="10dp"
                android:text="99"
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </RelativeLayout>

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

</RelativeLayout>

如何使我的屏幕看起来与所需的屏幕相同?

【问题讨论】:

  • 发布您的代码
  • 显示你的 XML 。
  • @KingofMasses 我已经编辑了我的帖子并包含了我的 xml。

标签: android fragment cardview


【解决方案1】:

试试下面的 xml 代码,把你的 ListView 放到 CardView 里面;

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:background="@color/color"
        android:id="@+id/cv1"
        card_view:cardElevation="3.5dp"
        card_view:cardBackgroundColor="#fff"
        card_view:cardCornerRadius="3dp"
        android:foreground="?android:attr/selectableItemBackground"
        xmlns:android="http://schemas.android.com/apk/res/android">

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

           <ListView
            android:id="@+id/study_level_list"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        </LinearLayout>

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

【讨论】:

  • 我会试试的。谢谢。
  • 成功了!!谢谢。我只需要搜索有关在 Fragment 上填充 customListView 的信息。
  • 我现在的声望不到 15 个,我的点赞不会反映。 (根据 Stackoverflow)。
【解决方案2】:

在卡片视图中添加您的 Recyclerview

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cv1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:background="@color/color"
    android:foreground="?android:attr/selectableItemBackground"
    card_view:cardBackgroundColor="#fff"
    card_view:cardCornerRadius="3dp"
    card_view:cardElevation="3.5dp">

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

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

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

并按如下方式更改您的适配器布局

<?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">


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

            <TextView
                android:id="@+id/lblProductName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="19dp"
                android:padding="10dp"
                android:text="Product Name"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/lblProductQuantity"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginTop="19dp"
                android:padding="10dp"
                android:text="99"
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </RelativeLayout>


</RelativeLayout>

【讨论】:

    【解决方案3】:

    将您的列表视图放入卡片视图中

    <android.support.v7.widget.CardView
                android:id="@+id/card_view"
                android:layout_width="fill_parent"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:layout_margin="5dp"
                card_view:cardCornerRadius="2dp"
                card_view:contentPadding="10dp">
        <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical" />
        </android.support.v7.widget.CardView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 1970-01-01
      • 1970-01-01
      • 2016-09-02
      相关资源
      最近更新 更多