Android 文本输入文本视图未按预期呈现
我的问题是,Android 文本输入文本视图未按预期呈现,android,android-constraintlayout,Android,Android Constraintlayout,我的问题是,textinputtext视图没有像我使用android:layout\u width=“match\u parent”所期望的那样展开以占据父视图的整个宽度。 下面的代码是应用程序的一个片段: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/re
textinputtext
视图没有像我使用android:layout\u width=“match\u parent”
所期望的那样展开以占据父视图的整个宽度。
下面的代码是应用程序的一个片段:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/constraintLayout">
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textInputLayout1"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="@+id/constraintLayout"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="@+id/constraintLayout"
android:layout_marginLeft="16dp"
app:layout_constraintRight_toLeftOf="@+id/guideline3"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textInputEditText1"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textInputLayout2"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toRightOf="@+id/textInputLayout1"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="@+id/constraintLayout"
android:layout_marginRight="16dp"
app:layout_constraintTop_toTopOf="@+id/textInputLayout1"
app:layout_constraintBottom_toBottomOf="@+id/textInputLayout1">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textInputEditText2"
android:layout_weight="1"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp"/>
</android.support.design.widget.TextInputLayout>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline3"
app:layout_constraintGuide_Percent="51"
android:orientation="vertical"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="216dp"/>
</android.support.constraint.ConstraintLayout>
将TextInputLayout元素的宽度设置为与父项匹配将TextInputLayout元素的宽度设置为与父项匹配您的代码非常好,但您可能正在使用较旧版本的ConstraintLayout
(例如alpha 4)。尝试更新到最新的alpha 6,这将解决您的问题(您还需要将app:layout\u constraintGuide\u Percent=“51”
替换为app:layout\u constraintGuide\u Percent=“0.5”
,因为有API更改)您的代码非常好,但您可能正在使用较旧版本的ConstraintLayout
(例如alpha 4)。尝试更新到最新的alpha 6,这将解决您的问题(您还需要将app:layout\u constraintGuide\u Percent=“51”
替换为app:layout\u constraintGuide\u Percent=“0.5”
)当这起作用时,我一打开可视化编辑器,它就会用0dp
替换match\u parent
,这是故意的行为吗?尝试使用android:layout\u width=“0dp”和android:layout\u weight=“1”的组合它又变小了。你能用布局编辑器设置元素的宽度吗?我输入的宽度是TextInputLayout的0dp
,TextInputItemXT的match\u parent
当这工作时,只要我打开可视化编辑器,它就会用0dp
替换match\u parent
,这是故意的吗haviour?尝试使用android:layout\u width=“0dp”和android:layout\u weight=“1”这两种组合,它已恢复为较小的。您可以使用布局编辑器设置元素的宽度吗?对于TextInputLayout,我输入的宽度是0dp
,对于TextInputText,则是match\u parent