Hi I have to make layout as below, edit text has to be in TextInputLayout
to have error and floating hint functionality, and spinner on the right must have underline. My question is how to do it, because when I'm adding EditText
into TextInputLayout
there is a padding bellow and both underlines aren't in the same line. Is it possible to measure somehow this error container height?
So there are two possibility to do this:
errorEnabled
as false and create custom TextView
with error text.TextView
to the bottom of second view with style and font size which can be found in TextInputLayout
constructor. I'm not using this method but in my case it is 12sp.This is a common problem and one that I had to deal with myself just the other day. You can always take a look at the measurements on the guidelines here rather than needing to look into the code.
With regards to making a spinner match you can start with adding a background like this drawable
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="-1dp"
android:left="-1dp"
android:right="-1dp"
android:bottom="1dp" >
<shape android:shape="rectangle">
<padding android:top="4dp" android:bottom="4dp" />
<stroke android:width="1dp" android:color="@color/my_grey"/>
</shape>
</item>
</layer-list>
You'll probably want to add android:padding="0dp"
to the Spinner and rather than using one of th simple_...
layouts which add padding which does not match EditText, return a plain TextView as your view returned from the adapter but continue to use the simple_...
layout for the dropdown view, like the adapter example below
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
//convertView = mInflater.inflate(R.layout.support_simple_spinner_dropdown_item, parent, false);
convertView = new TextView(parent.getContext());
}
//if you want to mimick the floating hint behaviour from the edit text,
//you can animate the label visibility here
return populateView(position, convertView, parent);
}
private View populateView(int position, View convertView, ViewGroup parent) {
// in here set your values as you usually would
return convertView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.support_simple_spinner_dropdown_item, parent, false);
}
return populateView(position, convertView, parent);
}
Now provided your margins on the EditText and Spinner match, they will line up. Although in some layouts I have to set android:layout_marginTop="0dp"
on the Spinner
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With