-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vertical alignment of text not consistent #16
Comments
Could you find the total height of the hint text and the height of the view, then place the top of the hint half of its height above the middle of the view? |
Hi, main issue on my side is time, not finding where the problem is. If you feel like contributing, feel free to fork the project and submit a pull request that fixes the issue. The idea is to have the hint text aligned to the bottom of the EditText text when that one is empty. |
Ok! I've solved the problem. First of all I thought that the problem is in difference of styles of TextView and EditText (here is all ok). Then i started to check the java classes. So the problem is here: FloatingLabelTextViewBase: @Override
protected void afterLayoutInflated(Context context, AttributeSet attrs, int defStyle) {
super.afterLayoutInflated(context, attrs, defStyle);
// Load custom attributes
final int drawableRightId;
final int drawableLeftId;
final int drawablePadding;
final int inputWidgetTextAppearance;
final int inputWidgetTextColor;
final float inputWidgetTextSize;
if (attrs == null) {
inputWidgetTextAppearance = -1;
inputWidgetTextColor = 0xaa000000;
inputWidgetTextSize = getResources().getDimensionPixelSize(R.dimen.flw_defaultInputWidgetTextSize);
drawableLeftId = getDefaultDrawableLeftResId();
drawableRightId = getDefaultDrawableRightResId();
drawablePadding = 0;
} else {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingLabelTextViewBase, defStyle, 0);
drawableRightId = a.getResourceId(R.styleable.FloatingLabelTextViewBase_android_drawableRight, getDefaultDrawableRightResId());
drawableLeftId = a.getResourceId(R.styleable.FloatingLabelTextViewBase_android_drawableLeft, getDefaultDrawableLeftResId());
drawablePadding = a.getDimensionPixelSize(R.styleable.FloatingLabelTextViewBase_android_drawablePadding, 0);
inputWidgetTextAppearance = a.getResourceId(R.styleable.FloatingLabelTextViewBase_flw_inputWidgetTextAppearance, -1);
inputWidgetTextColor = a.getColor(R.styleable.FloatingLabelTextViewBase_flw_inputWidgetTextColor, 0xaa000000);
inputWidgetTextSize = a.getDimension(R.styleable.FloatingLabelTextViewBase_flw_inputWidgetTextSize, getResources().getDimensionPixelSize(R.dimen.flw_defaultInputWidgetTextSize));
a.recycle();
}
final TextView inputWidget = getInputWidget();
inputWidget.setCompoundDrawablesWithIntrinsicBounds(drawableLeftId, 0, drawableRightId, 0);
inputWidget.setCompoundDrawablePadding(drawablePadding);
if (inputWidgetTextAppearance != -1) {
inputWidget.setTextAppearance(getContext(), inputWidgetTextAppearance);
}
inputWidget.setTextColor(inputWidgetTextColor);
//inputWidget.setTextSize(TypedValue.COMPLEX_UNIT_PX, inputWidgetTextSize);
inputWidget.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (!isFloatOnFocusEnabled()) return;
if (hasFocus) {
floatLabel();
} else {
if (getInputWidget().getText().length() == 0) {
anchorLabel();
}
}
}
});
} if you comment this line //inputWidget.setTextSize(TypedValue.COMPLEX_UNIT_PX, inputWidgetTextSize); everything works fine! |
Also I've noticed that if I specify TypedValue.COMPLEX_UNIT_SP - everything works fine but the text size is big. |
Ok. But we need to be able to set the text size. So there must be something else we can do to make both work. |
Yes I know, but this is the direction to continue searching of the solution |
Ok! Here is another solution without commenting code blocks. I've done comparison of styles, text widgets and some experiments. Why does widgets behave like this - I don't know. But there is more beautiful (in my point of view) solution: FloatingLabelTextViewBase: final TextView inputWidget = getInputWidget();
inputWidget.setCompoundDrawablesWithIntrinsicBounds(drawableLeftId, 0, drawableRightId, 0);
inputWidget.setCompoundDrawablePadding(drawablePadding);
inputWidget.setTextColor(inputWidgetTextColor);
inputWidget.setTextSize(TypedValue.COMPLEX_UNIT_PX, inputWidgetTextSize);
if (inputWidgetTextAppearance != -1) {
inputWidget.setTextAppearance(getContext(), inputWidgetTextAppearance);
} Just replace the order of setTextSizу and setTextAppearance methods. In your app layouts (where you use FloatingLabelItemPicker and for example FloatingLabelEditText) you must specify two attributes for the custom Fl... widgets: app:flw_inputWidgetTextSize="14sp"
app:flw_inputWidgetTextAppearance="@android:style/TextAppearance.Medium.Inverse" I thinks much better to add these attributes to the library's layout files. P.S. These attrs is needed only by EditText and TextView (as I understand while was comparing their styles). |
Please note that instead of TextAppearance.Medium.Inverse we could use any TextAppearance styles. The main question is - to use the same appearance in EditText and TextView. |
But! Sorry for many messages. There is another problem - font size 14sp. When it uses 14sp - heights of widgets are not equal! I'll continue the searching |
Starting form the 18sp - all good |
Setting different drawable (with smaller size) - and the size of widget not increases. |
It seems that the text in not positionned identically vertically in the various floating label widgets :
EditText vs Pickers for example
The text was updated successfully, but these errors were encountered: