0

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?

Darren Burgess
  • 4,200
  • 6
  • 27
  • 43
l33t
  • 18,692
  • 16
  • 103
  • 180

1 Answers1

2

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.

Eugene van der Merwe
  • 4,390
  • 1
  • 35
  • 48
triggs
  • 5,890
  • 3
  • 32
  • 31
  • Thanks for the hint. If I use a `LinearLayout` I can't put the buttonbar at the bottom as in my sample code. Or can I? The Hotmail app solves this elegantly (the buttonbar shows a shadow too). Not sure what the best approach is... will try your hide/show code to begin with. – l33t Dec 14 '11 at 22:50
  • This solves my other issue: http://stackoverflow.com/questions/3393385/android-scrollview-in-relativelayout-with-buttonbar – l33t Dec 14 '11 at 23:00
  • You can with a linear layout you just need to wrap your layout in another linearlayout and set the orientation to vertical, also I've edited my answer with a note about visibility – triggs Dec 14 '11 at 23:29