我有这样的要求-我的活动在顶部包含一些文本视图,然后在中间包含可扩展列表视图,在底部包含一个按钮。我的问题是当我单击
可扩展列表视图时,扩展列表被容纳在按钮和可扩展列表视图之间的空间中。
我希望可扩展列表视图可以完全展开,并且按钮应该根据可扩展列表视图的包含内容向下移动。我已经使用滚动视图作为主要布局。
谢谢你
我有这样的要求-我的活动在顶部包含一些文本视图,然后在中间包含可扩展列表视图,在底部包含一个按钮。我的问题是当我单击
可扩展列表视图时,扩展列表被容纳在按钮和可扩展列表视图之间的空间中。
我希望可扩展列表视图可以完全展开,并且按钮应该根据可扩展列表视图的包含内容向下移动。我已经使用滚动视图作为主要布局。
谢谢你
这是具有 android:layout_weight 属性的 LinearLayout 吗?
Instead of using ScrollView as the main layout, use a LinearLayout but without the Button. For eg:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ExpandableListView
android:id="@+id/expandableListView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ExpandableListView>
</LinearLayout>
Now in code, add the Button as the footerView of the ExpandableListView as :
final ExpandableListView elv = (ExpandableListView) findViewById(R.id.expandableListView1);
Button btn = new Button(this);
elv.addFooterView(btn);
The button will always be present at the end of the ExpandableListView using this. Just as you want it to be.
您应该将可展开的 Listview 和按钮放在相对布局中,并在下面设置 align 是您的按钮,它适用于我。
自定义 ExpandableListView 教程
http://www.mysamplecode.com/2012/10/android-expandablelistview-example.html