【发布时间】:2019-12-26 16:04:28
【问题描述】:
我有一个AppCompatEditText 作为搜索栏和一个FrameLayout 作为“清除”按钮,都在ConstraintLayout 内:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
...
android:layoutDirection="ltr">
<FrameLayout
android:id="@+id/clearBtnLyt"
android:layout_width="36dp"
android:layout_height="36dp"
...
app:layout_constraintBottom_toBottomOf="@+id/editText1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/editText1">
... CONTENTS ...
</FrameLayout>
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
...
android:layoutDirection="rtl"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/clearBtnLyt"
app:layout_constraintTop_toBottomOf="@id/toolbar1" />
...
</androidx.constraintlayout.widget.ConstraintLayout>
ConstraintLayout 设置为从左到右,只有AppCompatEditText 是 RTL。这些视图在 Android Studio 的布局预览中得到了很好的展示。
但当我在装有 Android 8.0 操作系统的三星 Galaxy A5 (2017) 上运行该应用程序时,它看起来像这样:
我无法在AppCompatEditText 中输入任何内容或单击它,但“清除”按钮正在工作。我的手机也设置为从左到右。 我做错了什么?
【问题讨论】:
-
这里需要xml
-
@pankaj-kumar 我还写了
ConstraintLayout代码。请检查它。 -
为什么不把AppCompatEditText的layout_width设置成“match_parent”呢?
-
因为我们不能在
ConstraintLayout中使用match_parent。我们只能将约束和这些值用于ConstraintLayout的内容的layout_width或layout_height属性:0dp(match_constraint)、wrap_content或自定义值。
标签: android android-layout view android-edittext android-constraintlayout