屏障不适用于 viewstub,填充过多
Barrier not working with viewstub, too much padding
我正在尝试将屏障与 viewstub 结合使用,从而使 textinputlayout 膨胀。问题是,当设置文本错误时(例如,用户在其中输入了错误的内容),填充会变得一团糟。我会提供代码和截图。
Viewstub 用法
<ViewStub
android:id="@+id/app_default_company_name_et"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:inflatedId="@+id/app_default_company_name_et"
android:layout="@layout/app_standard_textinputlayout"
android:visibility="@{cValidator.companySwitchState}"
app:hint="@{cValidator.etCompanyNameHint}"
app:iType="@{0x00000001}"
app:layout_constraintEnd_toStartOf="@+id/app_default_company_ust_et"
app:layout_constraintStart_toStartOf="@+id/margin_left"
app:layout_constraintTop_toBottomOf="@+id/calibrate_user_data_company_text"
app:mText="@{cValidator.etCompanyName}"
app:mTextListener="@{cValidator.onCompanyNameChanged}"
app:vBility="@{cValidator.companySwitchState}"
app:vForm="@{cValidator.etCompanyNameEM}" />
<ViewStub
android:id="@+id/app_default_company_ust_et"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:inflatedId="@+id/app_default_company_ust_et"
android:layout="@layout/app_standard_textinputlayout"
android:visibility="@{cValidator.companySwitchState}"
app:hint="@{cValidator.etCompanyCodeHint}"
app:iType="@{0x00000001}"
app:layout_constraintEnd_toStartOf="@+id/margin_right"
app:layout_constraintStart_toEndOf="@+id/app_default_company_name_et"
app:layout_constraintTop_toTopOf="@+id/app_default_company_name_et"
app:mText="@{cValidator.etCompanyCode}"
app:mTextListener="@{cValidator.onCompanyCodeChanged}"
app:vBility="@{cValidator.companySwitchState}"
app:vForm="@{cValidator.etCompanyCodeEM}" />
<com.example.app.presentation.util.view.FixedInputTextLayout
android:id="@+id/app_intern_salutation_menu_dd"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:errorIconDrawable="@null"
app:layout_constraintEnd_toStartOf="@+id/app_standard_fullName_et"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/margin_left"
app:layout_constraintTop_toBottomOf="@+id/company_barrier"
app:validate_form="@{cValidator.ddSalutationEM}">
<com.example.app.presentation.util.view.ExposedDropDown
android:id="@+id/calibrate_user_data_salutation_dropdown"
android:layout_width="match_parent"
android:layout_height="@dimen/tv_dropdown_height"
android:inputType="none"
android:textSize="@dimen/font_text_large"
app:dropdown_adapter="@{@stringArray/app_contact_form_headline_salutation_choice}"
app:dropdown_behavior="@{cValidator.salutationDropDownBehavior}"
app:dropdown_text="@{cValidator.ddSalutation}" />
</com.example.app.presentation.util.view.FixedInputTextLayout>
<com.example.app.presentation.util.view.FixedInputTextLayout
android:id="@+id/app_standard_fullName_et"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:hint="@string/app_contact_form_full_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/margin_right"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/app_intern_salutation_menu_dd"
app:layout_constraintTop_toTopOf="@+id/app_intern_salutation_menu_dd"
app:validate_form="@{cValidator.etFullNameEM}">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="@={cValidator.etFullName}"
android:textSize="@dimen/font_text_large" />
</com.example.app.presentation.util.view.FixedInputTextLayout>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/company_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="app_default_company_name_et,
app_default_company_ust_et" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/margin_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="16dp" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/margin_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="@dimen/spacing_large" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/middleMargin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Viewstub 膨胀布局
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="kotlin.jvm.functions.Function1" />
<import type="kotlin.Unit" />
<variable
name="vBility"
type="Boolean" />
<variable
name="vForm"
type="String" />
<variable
name="hint"
type="String" />
<variable
name="iType"
type="Integer" />
<variable
name="mText"
type="String" />
<variable
name="mPrefixText"
type="String" />
<variable
name="mEndIcon"
type="Integer" />
<variable
name="mTextListener"
type="Function1<String,Unit>" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="@{vBility}">
<com.example.app.presentation.util.view.FixedInputTextLayout
android:id="@+id/app_default_et"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:hint="@{hint}"
android:visibility="@{vBility}"
app:endIconMode="@{mEndIcon}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:prefixText="@{mPrefixText}"
app:validate_form="@{vForm}">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/app_default_ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="@{iType}"
android:text="@{mText}"
android:textSize="@dimen/font_text_large"
app:onTextChanged="@{mTextListener}" />
</com.example.app.presentation.util.view.FixedInputTextLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
图片:无错误设置
图片:设置错误
自动添加 200dp 填充(来自布局检查器的值)
解决这个问题的唯一办法就是不再使用障碍,但我想继续使用它们
好的,我已经设法解决了这个问题。我不得不从 viewstub_inflated_layout
中删除 constraintlayout
。这是解决方案
<data>
<import type="kotlin.jvm.functions.Function1" />
<import type="kotlin.Unit" />
<variable
name="vBility"
type="Boolean" />
<variable
name="vForm"
type="String" />
<variable
name="hint"
type="String" />
<variable
name="iType"
type="Integer" />
<variable
name="mText"
type="String" />
<variable
name="mPrefixText"
type="String" />
<variable
name="mEndIcon"
type="Integer" />
<variable
name="mTextListener"
type="Function1<String,Unit>" />
</data>
<com.example.app.presentation.util.view.FixedInputTextLayout
android:id="@+id/app_default_et"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:hint="@{hint}"
android:visibility="@{vBility}"
app:endIconMode="@{mEndIcon}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:prefixText="@{mPrefixText}"
app:validate_form="@{vForm}">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/app_default_ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="@{iType}"
android:text="@{mText}"
android:textSize="@dimen/font_text_large"
app:onTextChanged="@{mTextListener}" />
</com.example.app.presentation.util.view.FixedInputTextLayout>
我正在尝试将屏障与 viewstub 结合使用,从而使 textinputlayout 膨胀。问题是,当设置文本错误时(例如,用户在其中输入了错误的内容),填充会变得一团糟。我会提供代码和截图。
Viewstub 用法
<ViewStub
android:id="@+id/app_default_company_name_et"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:inflatedId="@+id/app_default_company_name_et"
android:layout="@layout/app_standard_textinputlayout"
android:visibility="@{cValidator.companySwitchState}"
app:hint="@{cValidator.etCompanyNameHint}"
app:iType="@{0x00000001}"
app:layout_constraintEnd_toStartOf="@+id/app_default_company_ust_et"
app:layout_constraintStart_toStartOf="@+id/margin_left"
app:layout_constraintTop_toBottomOf="@+id/calibrate_user_data_company_text"
app:mText="@{cValidator.etCompanyName}"
app:mTextListener="@{cValidator.onCompanyNameChanged}"
app:vBility="@{cValidator.companySwitchState}"
app:vForm="@{cValidator.etCompanyNameEM}" />
<ViewStub
android:id="@+id/app_default_company_ust_et"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:inflatedId="@+id/app_default_company_ust_et"
android:layout="@layout/app_standard_textinputlayout"
android:visibility="@{cValidator.companySwitchState}"
app:hint="@{cValidator.etCompanyCodeHint}"
app:iType="@{0x00000001}"
app:layout_constraintEnd_toStartOf="@+id/margin_right"
app:layout_constraintStart_toEndOf="@+id/app_default_company_name_et"
app:layout_constraintTop_toTopOf="@+id/app_default_company_name_et"
app:mText="@{cValidator.etCompanyCode}"
app:mTextListener="@{cValidator.onCompanyCodeChanged}"
app:vBility="@{cValidator.companySwitchState}"
app:vForm="@{cValidator.etCompanyCodeEM}" />
<com.example.app.presentation.util.view.FixedInputTextLayout
android:id="@+id/app_intern_salutation_menu_dd"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:errorIconDrawable="@null"
app:layout_constraintEnd_toStartOf="@+id/app_standard_fullName_et"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/margin_left"
app:layout_constraintTop_toBottomOf="@+id/company_barrier"
app:validate_form="@{cValidator.ddSalutationEM}">
<com.example.app.presentation.util.view.ExposedDropDown
android:id="@+id/calibrate_user_data_salutation_dropdown"
android:layout_width="match_parent"
android:layout_height="@dimen/tv_dropdown_height"
android:inputType="none"
android:textSize="@dimen/font_text_large"
app:dropdown_adapter="@{@stringArray/app_contact_form_headline_salutation_choice}"
app:dropdown_behavior="@{cValidator.salutationDropDownBehavior}"
app:dropdown_text="@{cValidator.ddSalutation}" />
</com.example.app.presentation.util.view.FixedInputTextLayout>
<com.example.app.presentation.util.view.FixedInputTextLayout
android:id="@+id/app_standard_fullName_et"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:hint="@string/app_contact_form_full_name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/margin_right"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/app_intern_salutation_menu_dd"
app:layout_constraintTop_toTopOf="@+id/app_intern_salutation_menu_dd"
app:validate_form="@{cValidator.etFullNameEM}">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="@={cValidator.etFullName}"
android:textSize="@dimen/font_text_large" />
</com.example.app.presentation.util.view.FixedInputTextLayout>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/company_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="app_default_company_name_et,
app_default_company_ust_et" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/margin_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="16dp" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/margin_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="@dimen/spacing_large" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/middleMargin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Viewstub 膨胀布局
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="kotlin.jvm.functions.Function1" />
<import type="kotlin.Unit" />
<variable
name="vBility"
type="Boolean" />
<variable
name="vForm"
type="String" />
<variable
name="hint"
type="String" />
<variable
name="iType"
type="Integer" />
<variable
name="mText"
type="String" />
<variable
name="mPrefixText"
type="String" />
<variable
name="mEndIcon"
type="Integer" />
<variable
name="mTextListener"
type="Function1<String,Unit>" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="@{vBility}">
<com.example.app.presentation.util.view.FixedInputTextLayout
android:id="@+id/app_default_et"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:hint="@{hint}"
android:visibility="@{vBility}"
app:endIconMode="@{mEndIcon}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:prefixText="@{mPrefixText}"
app:validate_form="@{vForm}">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/app_default_ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="@{iType}"
android:text="@{mText}"
android:textSize="@dimen/font_text_large"
app:onTextChanged="@{mTextListener}" />
</com.example.app.presentation.util.view.FixedInputTextLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
图片:无错误设置
图片:设置错误
自动添加 200dp 填充(来自布局检查器的值)
解决这个问题的唯一办法就是不再使用障碍,但我想继续使用它们
好的,我已经设法解决了这个问题。我不得不从 viewstub_inflated_layout
中删除 constraintlayout
。这是解决方案
<data>
<import type="kotlin.jvm.functions.Function1" />
<import type="kotlin.Unit" />
<variable
name="vBility"
type="Boolean" />
<variable
name="vForm"
type="String" />
<variable
name="hint"
type="String" />
<variable
name="iType"
type="Integer" />
<variable
name="mText"
type="String" />
<variable
name="mPrefixText"
type="String" />
<variable
name="mEndIcon"
type="Integer" />
<variable
name="mTextListener"
type="Function1<String,Unit>" />
</data>
<com.example.app.presentation.util.view.FixedInputTextLayout
android:id="@+id/app_default_et"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="@dimen/wrapContent"
android:layout_height="wrap_content"
android:hint="@{hint}"
android:visibility="@{vBility}"
app:endIconMode="@{mEndIcon}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:prefixText="@{mPrefixText}"
app:validate_form="@{vForm}">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/app_default_ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="@{iType}"
android:text="@{mText}"
android:textSize="@dimen/font_text_large"
app:onTextChanged="@{mTextListener}" />
</com.example.app.presentation.util.view.FixedInputTextLayout>