我的布局有问题。我有一个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一个接一个地排序,然后得到以下图像。有解决方案吗?
答案 0 :(得分:1)
我的CardView和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>
答案 1 :(得分:0)
用一种可以解决您问题的父级版式包装CardView
。