我的 CardView 和 TextInputLayout 有问题

I have a problem with my CardView and TextInputLayout

我的布局有问题。我有一个 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 一个接一个地排列,我得到了下图。有解决办法吗?

I have a problem with my CardView and TextInputLayout

您需要将包含 TextInputLayout 的两个 LinearLayout 包装到 CardView

中的单个 viewGroup

示例代码

<?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>

用一种可以解决您的问题的父布局封装您的 CardView