我有一个简单的垂直 LinearLayout
,其中顶部有一个 button
,下面有一个 Listview
。
我想要的是,当按钮
被按下时,它会隐藏(使用View.GONE)并且由它产生的空白空间由填充 ListView
。
但是经过千辛万苦,还是没能实现。
我尝试了 invalidate()
和 onDraw()
,我尝试将 layout_weight=1
给 ListView
,我也尝试了 forceLayout()
、requestLayout()
方法,但都没有用。
奇怪的是,如果有 EditText
或 TextView
或任何其他组件而不是 ListView
,它工作正常,即 Edittext
等去抓取隐藏Button
产生的空白区域。但在 ListView
的情况下,它不会发生。
最佳答案
这个东西在我的模拟器中完美运行
btn1 = (Button) findViewById(R.id.button1);
btn1.setOnClickListener( new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
new ProgressTask().execute();
btn1.setVisibility(8);
}
})
XML代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<ListView
android:id="@+id/itemlist"
android:layout_below="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
关于android - 隐藏按钮后如何用ListView填充空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11079257/