I have a problem with my layout. I have a CardView and inside I have a LinearLayout and inside of my LinearLayout, I have two TextInputLayout and one spinner, here is the code:
<?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>
My problem is that when I execute my code, my layout order the TextInputLayout one over another and I get the following image. Is there a solution for this?
I have a problem with my CardView and TextInputLayout
You need to wrap your both LinearLayout
that contains TextInputLayout
in to a single viewGroup
inside CardView
SAMPLE CODE
<?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>