【发布时间】:2015-09-09 16:11:23
【问题描述】:
晚上好, 我有以下布局,我想让编辑文本随处可点击。此外,如果 layout_height 设置为 match_parent,则编辑文本可点击区域的工作方式类似于 wrap_content。
这是布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:focusable="true"
android:focusableInTouchMode="true">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<RelativeLayout
android:id="@+id/relative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar">
<TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="20dp">
<EditText
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</TextInputLayout>
</RelativeLayout>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/relative">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<EditText
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/note_content"
android:background="@null"
android:gravity="top"/>
</TextInputLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
如何使编辑文本在滚动视图内的相对布局中随处可点击?
【问题讨论】:
-
澄清一下:您的意思是要单击布局中的任意位置以向 EditText 注册? (例如,如果用户单击 EditText 上方或下方,仍应选择 EditText)
-
其实编辑文本只有在文本所在的区域才可以点击。我希望它是完全可复制的。
-
EditText 在没有文字的时候不能点击吗?我错过了什么吗?
-
可点击但可点击区域为wrap_content