[英]How to prevent editText from overlapping other view?
I have created an android project to test out some of the
editText
behavior.我创建了一个 android 项目来测试一些
editText
行为。 So what I did was have two editText
in a Relative Layout.所以我所做的是在一个相对布局中有两个
editText
。 One editText
is above the other but then when the editText
above gets too large, it overlap with the bottom editText.一个
editText
位于另一个之上,但是当上面的editText
变得太大时,它会与底部的editText 重叠。 Is there a way to fixed this by shifting the other editText
downward 1 line to make space?有没有办法通过将另一个
editText
向下移动 1 行来腾出空间来解决这个问题?
Yes I am aware that you can limit the size of one of the editText
to prevent it from getting too large but that is not what I want.是的,我知道您可以限制
editText
之一的大小以防止它变得太大,但这不是我想要的。
I think you need this我想你需要这个
<ScrollView>
<RelativeLayout>
<EditText></EditText>
<EditText android:marginTop = "10dp"> </EditText>
</RelativeLayout>
</ScrollView>
OR或者
<RelativeLayout>
<ScrollView>
<EditText></EditText>
<EditText android:marginTop = "10dp"> </EditText>
</ScrollView>
</RelativeLayout>
It's better to use LinearLayout (with orientation=vertical) if you want to stack them but in case you want to stick with RelativeLayout this is how you can do it.如果您想堆叠它们,最好使用 LinearLayout(使用方向 = 垂直),但如果您想坚持使用 RelativeLayout,这就是您可以做到的。 The key is
android:layout_below
attribute.关键是
android:layout_below
属性。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edittext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello"
android:layout_alignParentTop="true"/>
<EditText
android:id="@+id/edittext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="baby"
android:layout_below="@+id/edittext1"
/>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.