对齐按钮时出现问题
我想对齐这些输入,使其右侧有两个自动完成框,右侧有一个较小的按钮。然而,我最终得到了一个涵盖所有内容的大型自动完成功能(第二个)。
<RelativeLayout
android:layout_alignParentBottom="true"
android:id="@+id/transport_search"
android:background="@color/dark_grey"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<AutoCompleteTextView
android:id="@+id/transport_autoCompleteFrom"
android:layout_width="fill_parent"
android:layout_weight="5"
></AutoCompleteTextView>
<Button
android:id="@+id/transport_switchDirection"
android:layout_toRightOf="@+id/transport_autoCompleteFrom"
android:layout_width="fill_parent"
android:layout_weight="1"
></Button>
<AutoCompleteTextView
android:id="@+id/transport_autoCompleteTo"
android:layout_width="fill_parent"
android:layout_weight="5"
></AutoCompleteTextView>
<Button
android:id="@+id/transport_go"
android:layout_toRightOf="@+id/transport_autoCompleteTo"
android:layout_width="fill_parent"
android:layout_weight="1"
></Button>
</RelativeLayout>
我做错了什么?
I want to align those inputs to have two autocomplete box on the right, on a smaller button on their right. However I end up with a large autocomplete (second one) covering everything.
<RelativeLayout
android:layout_alignParentBottom="true"
android:id="@+id/transport_search"
android:background="@color/dark_grey"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<AutoCompleteTextView
android:id="@+id/transport_autoCompleteFrom"
android:layout_width="fill_parent"
android:layout_weight="5"
></AutoCompleteTextView>
<Button
android:id="@+id/transport_switchDirection"
android:layout_toRightOf="@+id/transport_autoCompleteFrom"
android:layout_width="fill_parent"
android:layout_weight="1"
></Button>
<AutoCompleteTextView
android:id="@+id/transport_autoCompleteTo"
android:layout_width="fill_parent"
android:layout_weight="5"
></AutoCompleteTextView>
<Button
android:id="@+id/transport_go"
android:layout_toRightOf="@+id/transport_autoCompleteTo"
android:layout_width="fill_parent"
android:layout_weight="1"
></Button>
</RelativeLayout>
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在RelativeLayout中使用LinearLayout。下面显示了两个排成一行的按钮:
You can use LinearLayout inside RelativeLayout. Below shows two buttons in line:
如果您更喜欢使用RelativeLayout,也许以下内容可以让您更接近您想要实现的目标。
以下是此布局的屏幕截图。
此外,您可能还想看看如何使用 TableLayout 来获得类似的结果 < a href="https://stackoverflow.com/questions/5642404">Android 创建对齐字段布局
If you prefer to use RelativeLayout, perhaps the following gets you closer to what you're trying to achieve.
Following is a screenshot of this layout.
Also, you may want to take a look at how TableLayout was used for a similar result in Android Create aligned fields Layout