簡體   English   中英

CardView內部的單個ListView

[英]Single ListView inside a CardView

我有這樣的屏幕要求:

屏幕要求

但是我不能讓它那樣工作。 我最終制作了一個這樣的View:

實際

我正在使用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中的代碼,將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>

在卡片視圖中添加您的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>

將您的列表視圖放入名片視圖

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM