ryoung
ryoung

Reputation: 846

UI Layout Issues

First let me attempt to layout what I am trying to accomplish here.

EditText

EditText SearchButton

ListView (search result. there can be only one, ListView with adapter and height of wrap_content seems to work for this, there is a button to add the result to the ListView below. Once the add button is clicked this ListView collapses, which is exactly what I am after)

TextView (label for objects added)

ListView (list of objects added, again I'm using an adapter for the list row layout)

SaveButton

I was going to paste the code that I have but there is just too much to go through. The issues I am having are with the ListViews. Basically, the ListView that contains the objects added will end up pushing the SaveButton off of the screen. I have tried a ton of solutions laid out on this and many other sites but they just don't seem to work right.

Basically, I want the SaveButton to always be at the bottom and I don't want it to get pushed off the screen when the ListView gets too big. The only solution I have found to "work" was to explicitly set the height of the ListViews. However, this causes problems when going from tablet to phone (Nexus7 & Galaxy S3). I thought that using dip for sizes would prevent this from happening but apparently not.

If anyone has a good strategy for creating this type of layout that would be great. Or even a good resource for learning how to use Android's clunky UI system (it really leaves a bit to be desired).

Edit: here is my attempt at using a RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_background"
android:orientation="vertical" >

<EditText
    android:id="@+id/plan_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:ems="10"
    android:hint="@string/plan_name_hint"
    android:textColor="@color/text_color" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/object_search_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/plan_name"
    android:ems="10"
    android:hint="@string/search_objects_text"
    android:textColor="@color/text_color" >
</EditText>

<Button
    android:id="@+id/objects_search_button"
    style="@style/button_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/object_search_text"
    android:layout_below="@id/plan_name"
    android:layout_alignParentRight="true"
    android:background="@drawable/black_button"
    android:text="@string/search_objects_button_label" />

<ListView
    android:id="@+id/search_result"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/object_search_text"
    android:background="@color/main_background"
    android:textColor="@color/text_color" >
</ListView>

<TextView
    android:id="@+id/objects_list_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/search_result"
    android:paddingBottom="8dip"
    android:paddingLeft="8dip"
    android:text="@string/plan_objects_list_label"
    android:textColor="@color/text_color"
    android:textSize="22sp"
    android:textStyle="bold" />

<ListView
    android:id="@+id/plan_objects"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/objects_list_label"
    android:background="@color/main_background"
    android:textColor="@color/text_color" >
</ListView>

<Button
    android:id="@+id/save_plan_button"
    style="@style/button_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@drawable/black_button"
    android:paddingLeft="8dip"
    android:text="@string/save_button_label" />

Upvotes: 1

Views: 129

Answers (3)

ryoung
ryoung

Reputation: 846

It looks like the only real solution here is to use explicit sizes for the list views and plan accordingly for different screen sizes (i.e. create different layouts for different screens and outlined here.). I was hoping for something a little more generic. Oh well.

Upvotes: 0

Onur A.
Onur A.

Reputation: 3017

Make the SaveButton and ListView at the same hierarchy level. e.g if your parent layout is RelativeLayout in your SaveButton add this property android:layout_alignParentBottom="true"

Upvotes: 0

Gabe Sechan
Gabe Sechan

Reputation: 93569

If you think the Android UI system is clunky, you obviously haven't tried to understand it. For most things its extremely well designed.

If you want a certain view (or views) to always be at the bottom, then you want to make your screen a RelativeLayout and put android:layout_alignParentBottom="true" on those element(s). Then add android:layout_above="id" on whatever you want to be above them, where id is the id of the element you want at the bottom.

Upvotes: 2

Related Questions