android - 我的 CardView 和 TextInputLayout 有问题

标签 android android-layout android-cardview cardview

我的布局有问题。我有一个 CardView,里面有一个 LinearLayout,在我的 LinearLayout 里面,我有两个 TextInputLayout 和一个微调器,这里是代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:background="@color/White"
    tools:context=".Fragments.ProductsFragment">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <android.support.v7.widget.CardView
                    android:id="@+id/cvRuler"
                    xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    card_view:cardBackgroundColor="@color/colorPrimaryDark"
                    card_view:cardCornerRadius="10dp"
                    card_view:cardUseCompatPadding="true">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dp"
                        android:orientation="horizontal">

                        <android.support.design.widget.TextInputLayout
                            android:id="@+id/tilCodeBar"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textColorHint="@color/black"
                            app:hintEnabled="true">
                            <EditText
                                android:id="@+id/etBarCode"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="2"
                                android:ems="14"
                                android:hint="Código de Barras"
                                android:inputType="numberDecimal"
                                android:textColor="@color/black"/>
                        </android.support.design.widget.TextInputLayout>

                        <ImageButton
                            android:id="@+id/ibReadCode"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="0.5"
                            android:src="@drawable/ic_camera_light" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dp"
                        android:orientation="vertical">

                        <android.support.design.widget.TextInputLayout
                            android:id="@+id/tilDescProduct"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:textColorHint="@color/black"
                            app:hintEnabled="true">

                            <EditText
                                android:id="@+id/etDescProduct"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:hint="Descripción del Producto"
                                android:inputType="none"
                                android:textColor="@color/black" />
                        </android.support.design.widget.TextInputLayout>

                    </LinearLayout>

                </android.support.v7.widget.CardView>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

我的问题是,当我执行我的代码时,我的布局将 TextInputLayout 一个接一个地排列,我得到了下图。有解决办法吗?

enter image description here

最佳答案

I have a problem with my CardView and TextInputLayout

你需要把你的两个包裹起来 LinearLayout包含 TextInputLayout入单viewGroup里面CardView

示例代码

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/cvRuler"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    card_view:cardBackgroundColor="@color/colorPrimaryDark"
                    card_view:cardCornerRadius="10dp"
                    card_view:cardUseCompatPadding="true">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_margin="10dp"
                            android:orientation="horizontal">

                            <android.support.design.widget.TextInputLayout
                                android:id="@+id/tilCodeBar"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textColorHint="@android:color/black"
                                app:hintEnabled="true">

                                <EditText
                                    android:id="@+id/etBarCode"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_weight="2"
                                    android:ems="14"
                                    android:hint="Código de Barras"
                                    android:inputType="numberDecimal"
                                    android:textColorHint="@android:color/black" />
                            </android.support.design.widget.TextInputLayout>

                            <ImageButton
                                android:id="@+id/ibReadCode"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="0.5"
                                android:src="@drawable/ic_close" />
                        </LinearLayout>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_margin="10dp"
                            android:orientation="vertical">

                            <android.support.design.widget.TextInputLayout
                                android:id="@+id/tilDescProduct"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:textColorHint="@android:color/black"
                                app:hintEnabled="true">

                                <EditText
                                    android:id="@+id/etDescProduct"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:hint="Descripción del Producto"
                                    android:inputType="none"
                                    android:textColorHint="@android:color/black" />
                            </android.support.design.widget.TextInputLayout>

                        </LinearLayout>

                    </LinearLayout>
                </android.support.v7.widget.CardView>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</FrameLayout>

enter image description here

关于android - 我的 CardView 和 TextInputLayout 有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55963246/

相关文章:

java - 仅 RecyclerView 的第一个 CardView 被着色

android - 如何让两个cardview水平滚动?

android - HTML5 音频无法在 PhoneGap 应用程序中播放(可以使用媒体吗?)

android - 适用于 Android 的 Xamarin UITest ScrollDownTo 真的很慢

java - 如何从该数组列表中获取值并显示包含该值的文本?

android - 在android中创建带有两侧弯曲角的矩形可绘制对象

android - 在哪里可以找到 styles.xml 文件?

android - 如何移除非消耗品并再次购买(在测试 Android 应用程序时)?

android - Android 界面生成器(用户界面设计器)

android - Cardview 角(边)显示颜色较深,如何解决?