davidcesarino
davidcesarino

Reputation: 16209

Layout problem: Listview pushes View outside screen

I have two textviews, a listview (this is a listactivity, by the way) and a datepicker. All is supposed to be displayed in this order, vertically.

The problem is that the ListView is pushing the datepicker below the screen, to the depths of the unseen world. I want the datepicker to have its own space, fixed at the bottom, while the listview grows as needed, but still allowing datepicker to have its own space.

+/- like this:

~~~~~~~~~~~~~~~ screen top

TextView 1

TextView 2

|

|

|

| ListView [*]

|

|

|

DatePicker (stays here no matter how much List grows or shrinks

~~~~~~~~~~~~~~~ screen bottom

[*] -> This listview will scroll a lot, but won't hide datepicker!

I know it's very lazy to ask for ready code, but could you guys share a light? This is driving me crazy. I've tried millions of combinations I believe.

Thank you a lot. This is all I need to finish my first app! :-(

Upvotes: 0

Views: 1214

Answers (1)

Cristian
Cristian

Reputation: 200080

Use RelativeLayout:

<RelativeLayout>
  <!-- other stuff goes here -->
  <DatePicker
    android:id="@+id/some_id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"/>
  <ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/some_id"/>
</RelativeLayout>

By the way, I just gave you the basic and important part... you will need to complete the code (for instance, you have to give a width and height to the RelativeLayout tag, put your TextViews, etc.)

Upvotes: 3

Related Questions