首先让我尝试在这里尝试完成我想要完成的工作。用户界面布局问题
的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" />
如果您想要保留一个LinearLayout,另一种方法是将'layout_weight'设置为您想展开/收缩以适应屏幕的任何ListView。 – Geobits
当弹出键盘时,会使所有内容都缩小的Geobit。 – ryoung
这使应用程序崩溃:CastException:android.widget.Button不能转换为android.widget.ListView – ryoung