Android:像Hotmail应用程序一样隐藏按钮栏



考虑Android的Hotmail应用程序。查看邮件时,底部会出现三个按钮:[标记已读][标记未读][删除]当你取消选中时,按钮又消失了。

这个的布局是什么?我试过这个,但它在底部产生滚动问题(无法看到最后一个项目):

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black" />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@android:color/darker_gray"
    android:orientation="horizontal"
    android:paddingLeft="5dip"
    android:paddingRight="5dip"
    android:paddingTop="5dip" >
    <Button
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:enabled="false"
        android:text="@string/mark_read" />
</LinearLayout>

那么,我还需要显示/隐藏这些东西吗?

改变bottom linearlayout的可见性将显示/隐藏它。你需要给它一个id,然后是

LinearLayout bottomLayout = (LinearLayout)findViewById(R.id.someId);
bottomLayout.setVisibility(View.GONE)// or View.VISIBLE

至于滚动问题,这是因为RelativeLayout覆盖了视图组件,所以你可以显示/隐藏覆盖在ListView底部的按钮,或者将RelativeLayout更改为LinearLayout,以便ListView在按钮之前结束并更改可见性。

虽然我不确定这将看起来很好,当你突然显示按钮和ListView必须调整自己的大小。

可视性说明

setVisibility(View.GONE);

将从布局中删除视图,其他组件可能因此而调整大小。然而使用

setVisibility(View.INVISIBLE);

保留视图在布局中占用的空间,只是使视图不可见,并且不会发生大小调整。

相关内容

最新更新