TextView和EditText溢出

时间:2015-04-20 16:21:58

标签: android android-layout textview

我需要在一行中显示和TextView(标签),EditText(输入)和TextView(后缀)。

我遇到的问题是 - 如果标签TextView太长,那么EditText和Suffix TextView就不会被绘制。

这是我的代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
    android:layout_weight="0"
    android:padding="5dp"
    android:text="Label"
    android:id="@+id/label_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<EditText
    android:layout_weight="1"
    android:id="@+id/input_edit_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColorHint="@color/dark_grey"
    android:textColor="@color/black"
    android:hint="text.." />

<TextView
    android:padding="5dp"
    android:layout_weight="0"
    android:text="Suffix.."
    android:background="@color/lite_grey"
    android:id="@+id/suffix_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

所以我想要的是 - 即使标签超过2-3行,EditText出现后跟另一个TextView。

任何指针都会受到赞赏。

谢谢!

修改 我添加了一些“图表”,这样你就可以理解我想做的更好了。

EditText的标签可以是任意长度(2/3行),所以每当标签完成时我想要一个EditText启动(后面是另一个显示后缀的TextView ..)

.. What I want ![这显示了2行标签和TextView ..] 2 line label and EditText

编辑2:感谢您的回复!我认为@questioner真的明白我想要做什么,即我希望你的3个视图转移到其他行,这样他们的行为就像他们是一个视图 - 并且他建议我必须为此找到一个库! / p>

4 个答案:

答案 0 :(得分:1)

为什么不使用RelativeLayout代替LinearLayout,然后使用android:layout_below="@+id/..."android:layout_above="@+id/..." android:layout_toRightOf="@+id/..."android:layout_toLeftOf="@+id/..."

答案 1 :(得分:1)

这个怎么样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_gravity="center_vertical"
          android:layout_width="match_parent"
          android:layout_height="wrap_content">

<TextView
    android:padding="5dp"
    android:text="Label"
    android:id="@+id/label_text_view"
    android:layout_width="100dp"
    android:layout_gravity="center_vertical"
    android:layout_height="wrap_content"/>

<EditText
    android:layout_weight="1"
    android:id="@+id/input_edit_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:textColorHint="@color/dark_grey"
    android:textColor="@color/black"
    android:hint="text.."/>

<TextView
    android:padding="5dp"
    android:text="Suffix.."
    android:layout_gravity="center_vertical"
    android:background="@color/lite_grey"
    android:id="@+id/suffix_text_view"
    android:layout_width="100dp"
    android:layout_height="wrap_content"/>
</LinearLayout>

如果您希望3个视图移动到其他行,以便它们的行为类似于一个视图 - 您应该使用外部库。

答案 2 :(得分:0)

android:layout_weight="1"

对于每个视图,以便它们都占据相同数量的水平空间。

答案 3 :(得分:0)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1">

试试这个或请再扩展一下。

相关问题