简体   繁体   English

RelativeLayout包装中的Android TextView

[英]Android TextView in RelativeLayout wrapping

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. 我试图用一个左侧的列中的三个textViews和一个在右侧彼此相邻的两个按钮制作一个relativeLayout。 The problem is, when the first textView is short "ie 3 or 4 characters" the textViews below get wrapped whenever they are longer then the first textView. 问题是,当第一个textView短于“即3个或4个字符”时,下面的textView只要比第一个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>

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. 相对的问题是它会根据其他改变,如果您不希望这种情况发生,那么使用带有x行和y列的表布局会容易得多。

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. 伴随此,使用表布局允许您在特定列中进行特定的置零,或者使特定元素消耗多个列。

I have experienced something similar when creating a home screen widget. 创建主屏幕小部件时,我遇到了类似的情况。 As widgets have limited options, a TableLayout could not be used. 由于窗口小部件的选项有限,因此无法使用TableLayout。 I reverted to something that translates as follows to your situation: 我回复了一些内容,将其翻译为您的情况:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<LinearLayout
    android:id="@+id/RelativeLayout_class1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:orientation="vertical"
    android:visibility="visible" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="short" >
    </TextView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="shrt" >
    </TextView>

    <TextView
        android:id="@+id/TextView_class1_room"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="quite a bit longer" >
    </TextView>
</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:visibility="visible" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button 1" >
    </Button>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button 2" >
    </Button>
</LinearLayout>

</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM