I am facing some issue's with android material design drop-down menu items. Below are my issues with code and images. I implemented material design drop-down menu items and earlier the layout was absolutely fine. but after adding the array-list my layout width automatically get increased. below is mine code:
XML:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:hint="Product Category"
app:endIconMode="dropdown_menu"
app:hintTextColor="@color/colorPrimary">
<AutoCompleteTextView
android:id="@+id/productCategoryDropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textCursorDrawable="@null"
android:paddingStart="10dp" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="65dp"
android:layout_marginStart="5dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="5dp"
android:layout_weight="1.115"
android:hint="Product Weight"
app:hintTextColor="@color/colorPrimary">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="number"
android:textCursorDrawable="@null" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="65dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_weight="0.9"
android:hint="Weight Unit"
app:endIconMode="dropdown_menu"
app:hintTextColor="@color/colorPrimary">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/productWeightUnitDropdown"
android:paddingStart="5dp"
android:textCursorDrawable="@null"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
My Layout after XML:
Java code for same:
Dropdown = view.findViewById(R.id.productWeightUnitDropdown);
String[] weightUnit = new String[] {
"kg (Kilogram)",
"pcs (Piece)"
};
ArrayAdapter<String> weightUnitAdapter = new ArrayAdapter<>(
getActivity(),
R.layout.dropdown_item,
weightUnit
);
weightUnitDropdown.setAdapter(weightUnitAdapter);
Drop-Down Item.XML
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceSubtitle1">
</TextView>
After adding the java code width of the weight unit drop-down layout automatically increased. and now my layout looks like this. Not understanding why alignment gets disturbed.:
Also please help why in product category layout my selected item is coming over the hint. why it's not taking equal spacing like edit-text. The same issue is with the weight unit layout also. Compare product weight text and weight unit text, not in the same alignment. also, my keyboard opens when I click on this drop-down. I don't want a keyboard in this.


