【发布时间】:2014-08-08 14:08:20
【问题描述】:
分组展开/折叠时如何改变ExpandableListView的高度?
我想改变 ExpandableListView 的高度以适应其内容的高度,这样视图就不会在自身内部滚动。
这是主要活动的布局。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="jp.foo.android.activity.FooActivity"
tools:ignore="MergeRootFrame" />
这是主要活动片段的布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="jp.foo.android.fragment.FooFragment"
android:background="@color/category_bg">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:id="@+id/frameLayout">
<TextView
android:text="@string/subtitle_question_category"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/subtitle_category"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_horizontal|top"
android:textSize="20sp" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/frameLayout"
android:background="@drawable/category_list_bg_shape"
android:layout_marginTop="0dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:minHeight="300dp">
<LinearLayout
android:id="@+id/category_list_progressbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
android:visibility="gone">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/category_list"
android:transcriptMode="normal">
</ExpandableListView>
</FrameLayout>
</RelativeLayout>
以下是实际布局。
ExpandableListView 内容过多时会往里面滚动。
我想滚动整个屏幕。不仅滚动视图,而且带有标题。
【问题讨论】:
-
如果你将它的高度设置为 WRAP_CONTENT 它不应该滚动,你也不需要在展开/收缩时改变高度
-
@rupps 查看问题。我添加了我的布局。我已经尝试过 wrap_content,但这对我没有帮助:(
-
将父框架布局高度设置为 match_parent,使其足够大。如果元素不适合,ExpandableList 将滚动。还要检查这是否是您的问题stackoverflow.com/questions/15106471/…
-
如果您发布屏幕截图以找出您的布局会有所帮助
-
@rupps 屏幕截图已添加。