我已经创建了这个名为searchfragment的片段。下面是searchfragment的布局XML文件。不幸的是,设计并不像我想要的那样流畅。如何优化此布局XML文件以符合我的想法?
这里就是我想要它看起来像: 第一行:欢迎文本(的作品) 第二行:搜索输入字段(这样的作品,太) Thirt行(这里情况就变得复杂):应该有一个名为“搜索”的文本,然后是一个可以搜索的项目(例如名称,年份,价格)的微调器。然后是搜索按钮。接下来的事情是你可以对输出进行排序。因此,有一个文本“排序”,一个微调批评和排序按钮。最好的情况下,搜索部分应该对齐左侧,排序的权利,但仍居中。 第四行:输出字段。 现在,由于所有元素都显示在我的设备上,因此它们不在Eclipse的图形布局中。我已经尝试了好几个小时来让它工作,但是如果你没有找到你的对象,这很难。
长文本 - 短任务:请帮我优化我的设计。
searchfragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:text="@string/welcome" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="@string/edit_message" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:layout_marginTop="8dp" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_for" />
<Spinner
android:id="@+id/criterion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:entries="@array/searcharray"
android:prompt="@string/prompt" />
<Button
android:id="@+id/btnSubmit"
android:layout_width="136dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/android"
android:onClick="sendMessage"
android:text="@string/button_send" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sort_for"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Spinner
android:id="@+id/sort"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:entries="@array/sortarray"
android:prompt="@string/prompt" />
</LinearLayout>
<Button
android:id="@+id/sort_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/android"
android:onClick="sortAgain"
android:text="@string/button_send" />
</LinearLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/showResults"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</ScrollView>
</LinearLayout>
我已经添加了当前设计的照片。周围有红框的空间是第三个“行”,应该改变。第二个微调是(我不知道为什么)太宽。它应该和第一个一样广泛。那么所有的元素应该是相同的高度,元素应该居中。
这将有助于张贴布局的图像你会喜欢实现。 – kdroider 2013-02-13 08:48:49
完成。感谢你的帮助。 – chrissik 2013-02-13 09:06:37