如何使多行EditText使用Linear或RelativeLayout的剩余空间

姆本宁

我知道layout_weight和其他技巧,但是当我的EditText太大而无法容纳一行时,就会发生问题。

假设我有一个复选框,editText和一个箭头imageView,我想要这样的东西,复选框左对齐,箭头右对齐:

*   |Some very long text that  |  >
    |wraps                     |

但是我的EditText滚动而不是环绕。

我愿意使用RelativeLayouts或任何其他布局,我只希望避免嵌套太多的布局。

编辑:到目前为止,我的XML如下所示。我已经尝试使用RelativeLayout失败了。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<Checkbox android:id="@+id/left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0"/>
<EditText
    android:id="@+id/edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:background="@null"
    android:imeOptions="flagNoExtractUi"
    android:inputType="textImeMultiLine|textCapSentences"
    android:singleLine="false"
    android:textColor="@color/dark_gray"
    android:textColorHint="@color/medium_gray"
    android:layout_weight="1"
    android:drawable="@drawable/check/>
<ImageView
    android:id="@+id/right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:src="@drawable/arrow" />
</LinearLayout>
萨塔克·米塔尔(Sarthak Mittal)

我认为这个想法行得通:

使用RelativeLayout,将复选框设置为AlignParentLeft,将箭头设置为AlignParentRight,并在EditText上设置以下属性:

将其宽度设置为match_parent,将高度设置为wrap_content,设置为toRightOf复选框和toLeftOf箭头。

也许这可以解决您的问题

我在说这个:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp" >

<Checkbox
    android:id="@+id/left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
   />

<EditText
    android:id="@+id/edit_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/right"
    android:layout_toRightOf="@+id/left"
    android:inputType="textMultiLine" 
    />

<ImageView
    android:id="@+id/right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_launcher" />

</RelativeLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章