2013-08-07 84 views
1

首先让我尝试在这里尝试完成我想要完成的工作。用户界面布局问题

的EditText

的EditText搜索按钮

的ListView(搜索结果。只能有一个,的ListView带适配器和WRAP_CONTENT的高度似乎对这项工作,有一个按钮将结果添加到下面的ListView中,一旦添加按钮被点击,这个ListView会崩溃,这正是我所追求的)

的TextView(标签添加的对象)

的ListView(对象列表中所增加,再次我使用列表行布局适配器)

SaveButton

我正想粘贴我拥有的代码,但是有太多可以通过的代码。我遇到的问题是与ListViews。基本上,包含添加对象的ListView最终会将屏幕上的SaveButton关闭。我已经尝试了大量的解决方案,并在其他许多网站上安排,但他们似乎并没有正确的工作。

基本上,我希望SaveButton始终位于底部,我不希望它在ListView变得太大时被推离屏幕。我发现“工作”的唯一解决方案是明确设置ListView的高度。但是,这会导致从平板电脑到手机的问题(Nexus7 & Galaxy S3)。我认为使用dip尺寸可以防止这种情况发生,但显然不会。

如果任何人有一个很好的策略来创建这种类型的布局将是伟大的。或者甚至是学习如何使用Android笨重的UI系统的好资源(它真的有点不尽人意)。

编辑:这是我在使用的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" /> 

回答

0

它看起来像只有真正解决这里是相应地使用显式尺寸列表视图和计划不同的屏幕尺寸(即创建不同的屏幕不同的布局和outlined here。)。我希望有一些更通用的东西。好吧。

2

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

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

+1

如果您想要保留一个LinearLayout,另一种方法是将'layout_weight'设置为您想展开/收缩以适应屏幕的任何ListView。 – Geobits

+0

当弹出键盘时,会使所有内容都缩小的Geobit。 – ryoung

+0

这使应用程序崩溃:CastException:android.widget.Button不能转换为android.widget.ListView – ryoung

0

使SaveButtonListView处于相同的层级。例如,如果你的父母布局是RelativeLayoutSaveButton添加该属性android:layout_alignParentBottom="true"