【问题标题】:Android: Hidden buttonbar like in Hotmail appAndroid:Hotmail 应用程序中的隐藏按钮栏
【发布时间】:2011-12-14 22:06:43
【问题描述】:

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

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

【问题讨论】:

    标签: android show-hide buttonbar


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的提示。如果我使用LinearLayout,我不能像在我的示例代码中那样将按钮栏放在底部。或者我可以吗? Hotmail 应用程序优雅地解决了这个问题(按钮栏也显示了阴影)。不确定最好的方法是什么......将尝试您的隐藏/显示代码开始。
    • 这解决了我的另一个问题:stackoverflow.com/questions/3393385/…
    • 您可以使用线性布局,您只需将布局包装在另一个线性布局中并将方向设置为垂直,我还编辑了我的答案并附上了关于可见性的注释
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    相关资源
    最近更新 更多