Android TextView 中的RelativeLayout 包装
我正在尝试制作一个relativeLayout,其中左侧的一列中包含三个文本视图,右侧的两个按钮彼此相邻。问题是,当第一个 textView 很短(即 3 或 4 个字符)时,只要下面的 textView 比第一个 textView 长,它们就会被换行。我不希望这样,并且希望他们尽可能地使用按钮。我知道我可能缺少一个参数或类似的东西。有人可以帮助我吗?
<LinearLayout android:id="@+id/LinearLayout02" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/RelativeLayout_class1" android:visibility="visible">
<TextView android:layout_width="wrap_content" android:text="@+id/TextView01" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:id="@+id/TextView_class1_name" android:textColor="@color/Button_Text1"></TextView>
<TextView android:layout_width="wrap_content" android:text="@+id/TextView01" android:layout_below="@+id/TextView_class1_name" android:layout_height="wrap_content" android:layout_alignLeft="@+id/TextView_class1_name" android:layout_alignRight="@+id/TextView_class1_name" android:id="@+id/TextView_class1_building" android:textColor="@color/Button_Text1"> </TextView>
<TextView android:text="@+id/TextView01" android:layout_below="@+id/TextView_class1_building" android:layout_alignLeft="@+id/TextView_class1_building" android:layout_alignRight="@+id/TextView_class1_building" android:id="@+id/TextView_class1_room" android:textColor="@color/Button_Text1" android:layout_height="wrap_content" android:width="0dip" android:layout_width="wrap_content"></TextView>
<Button android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Button_class1_map" android:minHeight="@dimen/button_small_size" android:minWidth="@dimen/button_small_size" android:maxHeight="@dimen/button_small_size" android:maxWidth="@dimen/button_small_size" android:text="@string/text_map" android:layout_centerVertical="true"></Button>
<Button android:layout_toLeftOf="@+id/Button_class1_map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/Button_class1_map" android:layout_alignBottom="@+id/Button_class1_map" android:id="@+id/Button_class1_edit" android:minHeight="@dimen/button_small_size" android:minWidth="@dimen/button_small_size" android:maxHeight="@dimen/button_small_size" android:maxWidth="@dimen/button_small_size" android:text="@string/text_edit" android:layout_centerVertical="true"></Button>
</RelativeLayout>
</LinearLayout>
I am trying to make a relativeLayout with three textViews in a column on the left and two buttons next to each other on the right. The problem is, when the first textView is short "i.e. 3 or 4 characters" the textViews below get wrapped whenever they are longer then the first textView. I don't want this and want them to go all the way to the buttons if possible. I know I'm probably missing a parameter or something similar. Can anybody help me?
<LinearLayout android:id="@+id/LinearLayout02" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/RelativeLayout_class1" android:visibility="visible">
<TextView android:layout_width="wrap_content" android:text="@+id/TextView01" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:id="@+id/TextView_class1_name" android:textColor="@color/Button_Text1"></TextView>
<TextView android:layout_width="wrap_content" android:text="@+id/TextView01" android:layout_below="@+id/TextView_class1_name" android:layout_height="wrap_content" android:layout_alignLeft="@+id/TextView_class1_name" android:layout_alignRight="@+id/TextView_class1_name" android:id="@+id/TextView_class1_building" android:textColor="@color/Button_Text1"> </TextView>
<TextView android:text="@+id/TextView01" android:layout_below="@+id/TextView_class1_building" android:layout_alignLeft="@+id/TextView_class1_building" android:layout_alignRight="@+id/TextView_class1_building" android:id="@+id/TextView_class1_room" android:textColor="@color/Button_Text1" android:layout_height="wrap_content" android:width="0dip" android:layout_width="wrap_content"></TextView>
<Button android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Button_class1_map" android:minHeight="@dimen/button_small_size" android:minWidth="@dimen/button_small_size" android:maxHeight="@dimen/button_small_size" android:maxWidth="@dimen/button_small_size" android:text="@string/text_map" android:layout_centerVertical="true"></Button>
<Button android:layout_toLeftOf="@+id/Button_class1_map" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/Button_class1_map" android:layout_alignBottom="@+id/Button_class1_map" android:id="@+id/Button_class1_edit" android:minHeight="@dimen/button_small_size" android:minWidth="@dimen/button_small_size" android:maxHeight="@dimen/button_small_size" android:maxWidth="@dimen/button_small_size" android:text="@string/text_edit" android:layout_centerVertical="true"></Button>
</RelativeLayout>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不直接使用表格布局呢?设计可能会更容易一些,因为您正在讨论列和行。相对的问题是它会根据其他的而改变,如果你不希望这种情况发生,那么使用具有 x 行和 y 列的表格布局会容易得多。
除此之外,使用表布局允许您在特定列中进行特定归零或让特定元素消耗多个列。
Why not just use a table layout? It might be a little easier to design because you are talking about columns and rows. The problem with relative is that its going to change based on the others, if you don't want this to happen then using a table layout with x rows and y columns will be a lot easier.
Along with this, using table layout allows you to specific zeroing-in in a particular column or having a particular element consume more than one column.
我在创建主屏幕小部件时经历过类似的事情。由于小部件的选项有限,因此无法使用 TableLayout。我恢复了一些内容,根据您的情况翻译如下:
I have experienced something similar when creating a home screen widget. As widgets have limited options, a TableLayout could not be used. I reverted to something that translates as follows to your situation: