Android:在CardStackView中添加堆栈和当前卡之间的空间

时间:2017-06-20 10:32:52

标签: android android-cardview android-cards

我在我的应用中使用CardStackView。我已经编辑了布局,所以当选择卡片时我可以获得一张全高卡。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linear_list_card_item"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    app:stackHeaderHeight="160dp">

    <FrameLayout
        android:id="@+id/frame_list_card_item"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.99"
        android:background="@drawable/shape_rectangle_with_radius">

        <TextView
            android:id="@+id/text_list_card_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:textColor="@android:color/white"
            android:textSize="40sp"
            android:textStyle="bold"
            tools:text="12" />
    </FrameLayout>

    <View
        android:id="@+id/gab"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.01"
        android:animateLayoutChanges="true">

    </View>

</LinearLayout>

我尝试做的是在所选卡片和其下的堆栈之间添加一个空格。 How can I get the required output?

1 个答案:

答案 0 :(得分:1)

我试图回答这个问题,从前,我已经面对这个了。

您必须使用PercentRelativeLayout提供卡片的高度。

  <android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/linear_list_card_item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:stackHeaderHeight="160dp">

        <FrameLayout
            android:id="@+id/frame_list_card_item"
            android:layout_width="match_parent"
            android:background="@drawable/shape_rectangle_with_radius"
            app:layout_heightPercent="90%">

            <TextView
                android:id="@+id/text_list_card_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="20dp"
                android:textColor="@android:color/white"
                android:textSize="40sp"
                android:textStyle="bold"
                tools:text="12" />
        </FrameLayout>

        <View
            android:id="@+id/gab"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.01"
            android:animateLayoutChanges="true"
            android:visibility="gone">

        </View>

    </android.support.percent.PercentRelativeLayout>

不要忘记在build.gradle中添加此行(Module:app)

dependencies {
    compile 'com.android.support:percent:23.3.0'
}