Text in engraved TextView not working

I wrote the following function to create a text view. But some of the texts are not fully visible, so I get gravity centered_ horizontal | vertical but doesn't work. I do not see completely the following images in DATE and OUT DATE. This is how I want all text to be vertical and center horizontally

protected TextView createDefaultTabView(Context context) {
        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
        //textView.setPadding(0,0,0,25);

        textView.setLayoutParams(new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    [![enter image description here][1]][1]    TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
                outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
        textView.setAllCaps(true);

        int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        textView.setPadding(padding, padding, padding, padding + 10);

        return textView;
    }

      

enter image description here

+3


source to share


1 answer


Your height is TextView's

set to WRAP_CONTENT

, so the inner Gravity

does not affect vertical positioning (because there is no extra border to place itself).

If you want it to be vertically aligned, you need to set the TextView's

PARENT gravity to, CENTER_VERTICAL

or set the TextView's height to MATCH_PARENT

.



Any of these will give you the effect you are looking for.

+1


source







All Articles