简体   繁体   English

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

[英]Android: Add space between stack and current card in CardStackView

I'm using CardStackView in my app. 我在我的应用程序中使用CardStackView I've edited the layout so I can get a full height card when a card is selected. 我已经编辑了布局,以便在选择卡片时可以得到一张全高卡片。

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

What I'm trying to do is to add a space between the selected card and the stack under it. 我正在尝试做的是在所选卡与其下面的堆栈之间添加一个空间。 如何获得所需的输出?

I am trying to answer this question, once upon a time, I have faced this. 我试图回答这个问题,曾几何时,我曾经面对过这个问题。

You have to provide the height of the card using PercentRelativeLayout. 您必须使用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>

Don't forget to add this line in build.gradle (Module:app) 不要忘记在build.gradle(Module:app)中添加此行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM