2017-06-20 86 views
0

我在我的應用中使用CardStackView。我編輯了佈局,以便在選擇卡時可以獲得全高卡。Android:在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

我想回答這個問題,曾幾何時,我曾經遇到過這個問題。

您必須使用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加入這一行(模塊:APP)

dependencies { 
    compile 'com.android.support:percent:23.3.0' 
} 
相關問題