0

考虑适用于 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>

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

4

1 回答 1

2

更改底部线性布局的可见性将显示/隐藏它。你需要给它一个 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);

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

于 2011-12-14T22:30:17.703 回答