android - 隐藏按钮后如何用ListView填充空白区域

标签 android android-layout android-listview android-button

我有一个简单的垂直 LinearLayout,其中顶部有一个 button,下面有一个 Listview
我想要的是,当按钮被按下时,它会隐藏(使用View.GONE)并且由它产生的空白空间由填充 ListView
但是经过千辛万苦,还是没能实现。

我尝试了 invalidate()onDraw(),我尝试将 layout_weight=1ListView ,我也尝试了 forceLayout()requestLayout() 方法,但都没有用。

奇怪的是,如果有 EditTextTextView 或任何其他组件而不是 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/

相关文章:

android - Intel XDK 无法安装调试模块

android - 如何在按钮上设置位图?

android - 得到 threadid=1 : thread exiting with uncaught exception (group=0x41088930) on listview

android - 单击项目时取消选中项目

android - 使用键盘时,ListView 不会滚动到末尾

android - HTML5 音频标签在 Android 中不起作用

android - Mobile Firemonkey 应用本地化

android - 如何使用字符串通过变量名获取按钮?

android - 如何在 Android 的布局 XML 文件中设置 View 的属性?

android - 根据屏幕高度选择不同的布局目录