Android - Material.io - TextInputLayout 在 LinearLayout 中不起作用

标签 android layout

我是 Android 和 Material.io 新手

我想创建一个表单,供用户在我的应用程序中创建实体,但如果不使用布局,我只能看到按钮。如果我不使用布局并且使用多个 TextInput,它们只会堆叠在完全相同的位置:

    <?xml version="1.0" encoding="utf-8"?>
    <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"
        tools:context=".CreateTableActivity">
       <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginStart="1dp"
            android:layout_marginTop="1dp"
            android:layout_marginEnd="1dp"
            android:layout_marginBottom="1dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/textInputLayout"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="20dp"
                android:layout_marginStart="20dp"
                android:layout_marginEnd="20dp"
                android:hint="@string/create_table_table_name"
                android:inputType="text"
                app:boxStrokeColor="@color/colorAccent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:placeholderText="@string/create_table_table_name_placeholder"
                app:startIconTintMode="src_in">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/textInputName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="text"
                    />
            </com.google.android.material.textfield.TextInputLayout>
        </LinearLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>

我做错了什么?

提前致谢

最佳答案

请尝试这个:

<?xml version="1.0" encoding="utf-8"?>
<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">

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="1dp"
        android:layout_marginTop="1dp"
        android:layout_marginEnd="1dp"
        android:layout_marginBottom="1dp"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/textInputLayout"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:layout_marginStart="20dp"
            android:layout_marginEnd="20dp"
            android:hint="@string/accept"
            android:inputType="text"
            app:boxStrokeColor="@color/colorAccent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:placeholderText="@string/create_table_table_name_placeholder"
            app:startIconTintMode="src_in">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/textInputName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text"
                android:text="asdasasdasd" />
        </com.google.android.material.textfield.TextInputLayout>
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

关于Android - Material.io - TextInputLayout 在 LinearLayout 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59861522/

相关文章:

c# - C#中的布局管理器

java - 想知道 JFrames (BorderLayout) 的区别

android - 在 Drawable 中将图像源设置为 Bitmap

java - 如何将多个 edittext 值传递到 Arraylist 中,然后将其发送到另一个 Activity ?

android - 获取错误 ld.exe : error: cannot find -lgnuSTL_shared in ndk on compiling tbb source files

android - 媒体播放器同时播放多个文件

jquery - 页面布局仅在 Opera 中中断,这很奇怪吗?

CSS 问题,带有左右边栏的固定内容区域?

android - Kotlin Android 扩展与 Android 数据绑定(bind)库,内存使用情况

android - 是否可以用displayImage()设置ImageSize?