Code Monkey home page Code Monkey logo

Comments (11)

AOrobator avatar AOrobator commented on July 2, 2024

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?

from android-floatinglabel-widgets.

vpratfr avatar vpratfr commented on July 2, 2024

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.

from android-floatinglabel-widgets.

demogorgorn avatar demogorgorn commented on July 2, 2024

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!

from android-floatinglabel-widgets.

demogorgorn avatar demogorgorn commented on July 2, 2024

Also I've noticed that if I specify TypedValue.COMPLEX_UNIT_SP - everything works fine but the text size is big.

from android-floatinglabel-widgets.

vpratfr avatar vpratfr commented on July 2, 2024

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.

from android-floatinglabel-widgets.

demogorgorn avatar demogorgorn commented on July 2, 2024

Yes I know, but this is the direction to continue searching of the solution

from android-floatinglabel-widgets.

demogorgorn avatar demogorgorn commented on July 2, 2024

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).

from android-floatinglabel-widgets.

demogorgorn avatar demogorgorn commented on July 2, 2024

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.

from android-floatinglabel-widgets.

demogorgorn avatar demogorgorn commented on July 2, 2024

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

from android-floatinglabel-widgets.

demogorgorn avatar demogorgorn commented on July 2, 2024

Starting form the 18sp - all good

from android-floatinglabel-widgets.

demogorgorn avatar demogorgorn commented on July 2, 2024

Setting different drawable (with smaller size) - and the size of widget not increases.

from android-floatinglabel-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.