androidshow-hidebuttonbar

Android: Hidden buttonbar like in Hotmail app


Consider the Hotmail app for Android. When you check an e-mail item, three buttons appear at the bottom: [Mark Read] [Mark Unread] [Delete] When you uncheck it, the buttons go away again.

What's the layout for this? I've tried this, but it yields scrolling problems at the bottom (can't see last item):

<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>

Then, I also need to show/hide this stuff?


Solution

  • Changing the visibility of bottom linearlayout will show/hide it. You'll need to give it an id and then

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

    As for the scrolling problem, that occurs because the RelativeLayout overlays view components, so you can either show/hide the button overlaying the bottom of the ListView or change the Relativelayout to a LinearLayout so that the ListView ends before the button and change the visibility.

    Though I'm not sure this will look very good when you suddenly show the button and the ListView has to resize itself.

    Note on visibility

    setVisibility(View.GONE);
    

    will remove the view from the layout and other component may resize due to this. However using

    setVisibility(View.INVISIBLE);
    

    keeps the space the view took up in the layout and simply makes the view invisible and no resizing will occur.