【发布时间】:2019-03-26 12:42:48
【问题描述】:
我在高度 = match_parent 的滚动视图中放置了一个编辑文本,并希望它的高度等于滚动视图,但事实并非如此。它的高度类似于wrap_content,这意味着如果 EditText 中没有文本,我必须将光标指向第一“行”才能弹出软键盘,我想要的是我可以触摸屏幕上的任何位置(滚动视图)和软键盘弹出。
以下是布局,感谢您的帮助。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:gravity="top"
android:padding="10dp"
android:textSize="16sp"
android:textColor="@android:color/black">
</EditText>
</ScrollView>
<Button
android:id="@+id/btnPaste"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/paste"
android:gravity="center"
android:onClick="pasteData"
android:layout_marginLeft="5dp"
android:layout_marginRight="6dp"
android:layout_marginBottom="5dp"
android:background="@drawable/rounded_corner_button"
android:textColor="@android:color/white"/>
</LinearLayout>
布局捕获:
【问题讨论】:
-
你想让你的edittext可以滚动吗?
-
@primo 它是可滚动的,这就是我将它放在 ScrollView 中的原因。
-
你不需要为此使用滚动视图设置 android:layout_height="0dp" android:layout_weight="1" 到 EditText 并检查它是否工作
-
@VamsiSmart 感谢您的回复,我知道 EditText 它自己可以滚动,但它会有点“滞后”,将它放在 ScrollView 中将使“滚动”更顺畅。跨度>
-
尝试这里给出的解决方案stackoverflow.com/a/24428854/8101634
标签: android android-edittext height parent