4

我在嵌套的滚动视图中添加卡片。对于 LinearLayout 中顺序较低的卡片,卡片高度会自动增加。要了解这个问题,请注意第一张和最后一张卡片之间的卡片高度。最后一张牌的阴影比第一张要深,尽管两张牌是一样的。如何解决?

使用 appcompat v7:22.+ 作为 v7 库的依赖项。

这是我的卡片视图布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardElevation="1dp"
    android:layout_marginBottom="10dp"
    card_view:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_margin="10dp"
            xmlns:android="http://schemas.android.com/apk/res/android">

            <TextView
                android:id="@+id/hint"
                android:layout_width="0dp"
                android:text="ABC"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:textColor="@color/textHint"/>
            <TextView
                android:id="@+id/description"
                android:layout_width="0dp"
                android:text="DEFG BHJHKJ"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="1"/>
        </LinearLayout>

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

这就是我使用卡片视图的方式:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingtoolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <include
                layout="@layout/shared_activity_item"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:contentInsetStart="0dp"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#f3f3f3"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <LinearLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:orientation="vertical"
            android:gravity="center"
            >

            <TextView
                android:id="@+id/description"
                android:lineSpacingMultiplier="1.5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />


                <include
                android:id="@+id/date"
                layout="@layout/custom_detail_item_card" />
                <include
                android:id="@+id/confirmation"
                layout="@layout/custom_detail_item_card" />
                <include
                android:id="@+id/admit"
                layout="@layout/custom_detail_item_card" />

                <include
                android:id="@+id/meeting_point"
                layout="@layout/custom_detail_item_card" />



                <include
                android:id="@+id/pickup_time"
                layout="@layout/custom_detail_item_card" />

            <include
                android:id="@+id/dropoff_time"
                layout="@layout/custom_detail_item_card" />

                <include
                android:id="@+id/cancellation"
                layout="@layout/custom_detail_item_card" />

        </LinearLayout>
        <!--</android.support.v7.widget.CardView>-->
    </android.support.v4.widget.NestedScrollView>


</android.support.design.widget.CoordinatorLayout>

这是输出:http: //imgur.com/a/4Sr4p

4

0 回答 0