【发布时间】:2017-01-03 17:43:05
【问题描述】:
现在已经工作了很多小时,但我无法提出解决方案。
我有一个包含两个 CardView 的 LinearLayout。每个 CardView 包含两个 RelativeLayouts。一种始终可见、高度固定且可点击的 RelativeLayout。第二个 RelativeLayout 可以展开/折叠。 xml结构如下:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/cardview_one"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/visible_part_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toggleCardViews">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="visible part one"/>
</RelativeLayout>
<com.github.aakira.expandablelayout.ExpandableRelativeLayout
android:id="@+id/expandable_layout_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ael_expanded="true"
app:ael_duration="500"
app:ael_interpolator="linear"
app:ael_orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="expandable part one"/>
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/cardview_two"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/visible_part_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="toggleCardViews">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="visible part two"/>
</RelativeLayout>
<com.github.aakira.expandablelayout.ExpandableRelativeLayout
android:id="@+id/expandable_layout_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ael_expanded="false"
app:ael_duration="500"
app:ael_interpolator="linear"
app:ael_orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="expandable part two"/>
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我想要实现的是单击折叠的 cardVie 以展开它的可展开部分,同时折叠折叠的其他卡片视图。同时,我想将两个卡片视图都保留在屏幕边界内。它应该看起来像这样。
+--LinearLayout---+
| +--CardView1---+|
| |visible part ||
| |--------------||
| |exppanded part||
| |80% of screen|||
| | ||
| +--------------+|
| |
| +--CardView2---+|
| |visible part ||
| |20% of screen ||
| +--------------+|
+-----------------+
用户点击第一个 CardView 的可见部分后(反之亦然):
+--LinearLayout---+
| +--CardView1---+|
| |visible part ||
| |20% of screen ||
| +--------------+|
| +--CardView2---+|
| |visible part ||
| |--------------||
| |exppanded part||
| |80% of screen|||
| | ||
| +--------------+|
+-----------------+
目前,为了在折叠或展开时将两个卡片视图保持在屏幕内,尝试以编程方式更改卡片视图的权重属性,如this。此解决方案将两个卡片视图都保留在屏幕内,但过渡动画根本不流畅。我怀疑使用 ExpandableRelativeLayout 会导致问题。
有人遇到过同样的问题并想出了解决方案吗?任何帮助表示赞赏!
【问题讨论】:
-
也许可以使用这个库github.com/AAkira/ExpandableLayout
-
感谢您的评论,但我已经在使用这个库了。
-
我已经实现了同样的事情。为此,我创建了一个卡片视图,其中包含两种布局,一种用于折叠视图,另一种用于展开视图。能否请您发布所需的屏幕截图以便于理解?
标签: android