1

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

4

3 回答 3

2

如果你觉得 Android UI 系统笨拙,那你显然还没有尝试去理解它。对于大多数事情来说,它的设计非常好。

如果您希望某个视图(或多个视图)始终位于底部,那么您希望将屏幕设置为 RelativeLayout 并将 android:layout_alignParentBottom="true" 放在这些元素上。然后将 android:layout_above="id" 添加到您想要位于它们之上的任何内容上,其中 id 是您想要在底部的元素的 id。

于 2013-08-07T17:06:24.830 回答
0

看起来这里唯一真正的解决方案是为列表视图使用明确的大小,并针对不同的屏幕大小进行相应的规划(即为不同的屏幕创建不同的布局并在此处概述。)。我希望有一些更通用的东西。那好吧。

于 2013-08-14T21:03:09.490 回答
0

使SaveButtonListView在同一层次结构级别。例如,如果您的父布局RelativeLayout在您SaveButton添加此属性中android:layout_alignParentBottom="true"

于 2013-08-07T17:08:40.613 回答