【发布时间】:2020-08-03 05:27:46
【问题描述】:
所以我遇到了一个问题,我试图在 com.google.material 库的 TextInputLayout 下将我的 EditText 转换为 TextInputEditText。
我无法将 TextInputEdit 文本放在 TextInputLayout 之上 这是一个屏幕截图。
如您所见,它与顶部和左侧都有点偏离。
登录.xml
<com.google.android.material.textfield.TextInputLayout
android:layout_width="210dp"
android:layout_height="53dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:background="@drawable/roundedittext"
android:ems="10"
android:hint=" Email"
android:importantForAutofill="no"
android:inputType="textEmailAddress"
android:padding="5dp"
app:errorEnabled="true"
tools:layout_editor_absoluteX="101dp"
tools:layout_editor_absoluteY="366dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/signupemailfeild"
android:layout_width="210dp"
android:layout_height="47dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="210dp"
android:layout_height="47dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@drawable/roundedittext"
android:ems="10"
android:hint=" Password"
android:importantForAutofill="no"
android:inputType="textPassword"
android:padding="5dp"
app:errorEnabled="true"
app:passwordToggleEnabled="true"
tools:layout_editor_absoluteX="101dp"
tools:layout_editor_absoluteY="444dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/signuppasswordfeild"
android:layout_width="match_parent"
android:layout_height="47dp"
android:hint="Password"
android:inputType="textPassword"
tools:layout_editor_absoluteX="match_parent"
tools:layout_editor_absoluteY="match_parent" />
</com.google.android.material.textfield.TextInputLayout>
build.gradle(app:module)
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.google.firebase:firebase-database:19.3.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'com.github.castorflex.smoothprogressbar:library:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.mediarouter:mediarouter:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
}
更新:- 修复了 X 轴偏移 现在问题仅在于 Y 轴偏移。 Click Here For New Screenshot
【问题讨论】:
-
至少使用最新的稳定版本:implementation 'com.google.android.material:material:1.1.0'
-
在
TextInputEditText中使用android:layout_height="match_parent",在TextInputLayout中使用android:layout_height="wrap_content" -
@GabrieleMariotti 它确实有效,但仍然与顶部有一点偏移。这是截图link
-
删除TextInputLayout中的android:padding="5dp"
-
试过@GabrieleMariotti Y轴偏移仍然存在。内容完全可见,但偏移量仍然存在
标签: android android-studio android-layout material-components-android android-textinputlayout