Inherent TextView Padding - android

Does a TextView have some padding set by default? I'm trying to create two TextViews and I noticed that there's some padding in the TextViews without me explicitly setting it. If yes, then what's the value of it? Or where can I find more information on this?

Yes there exists font padding in android.
you could aswell disable it by
mTextView.setIncludeFontPadding(false);
or xml attribute
android:includeFontPadding="false"

Related

How do i make the constraintlayout wrap my textview programmatically

I've got a problem and have no idea how to fix it. I'm using a ConstraintLayout in android
I want to set my TextView to wrap_content programmatically but respect my constraints.
Now the issue is that if i set my constriantWidth to WRAP_CONTENT it does not respect the constraints it's given to it.
I've found that there is a solution in xml in it here:
Wrap_content view inside a ConstraintLayout stretches outside the screen
but in this issue no where is it described how to set the property of constrainedwidth to true programmaticly.
I've tried a few things but have not found a solution to my problem:
set.constrainWidth(textView.getId(),ConstraintSet.WRAP_CONTENT)
just wraps the content without keeping in my constriants that i've set.
I've also tried to set the constraintedWidth with the ConstraintLayout.Params but nothing happend.
And i have no clue if en how i can set constrainedWidth in my ConstraintSet.
and
set.constrainWidth(textView.getId(),ConstraintSet.MATCH_CONSTRAINT_WRAP)
Just makes my text a thin line of my text and doesn't show my text anymore.
If someone could help i would be very great full.
PS. Sorry for my english not a native speaker.
Use constrainDefaultWidth:
set.constrainDefaultHeight(textView.getId(), ConstraintSet.MATCH_CONSTRAINT_WRAP);

TextView with custom font isn't centered vertically

I need to use a custom font (VAG Rounded, probably not relevant) but the font changes how my TextViews react.
In the image below, you can see the two textviews with a black background. The left one use the custom font, the right one the default system font (Roboto ?). Both of them have the same xml properties and size, but the padding is not the same and more important, the left one isn't centered vartically !
How can I make the TextView draw its content well centered ?
You can try to remove your customs font padding from your text style (styles.xml):
<item name="android:includeFontPadding">false</item>
If this still doesn't work, i would set a general padding in your styles xml.
I think that you have to set android:layout_height="match_parent" and then also android:gravity="center"
then if you post also your source code we can give you more information
I could not change the font, and I wasn't going to edit each character using an editor (I don't even know what I should have done to fix it).
Si I ended up measure the difference with the default font and I added 0.15f * fontSize in the padding top...

How to set margin for all TextView using styles.xml

I've read from another post that it's possible to set attributes like color to every TextView in an application: Setting global styles for Views in Android. However, I can't set layout_margin nor layout_height and layout_width attribute using that method to any textView, using "android:textviewStyle". On the other hand, if I use the style attribute and reference it to a style with all the attributes above, it works. Is there a way that you can use global styles and still set margin?
Thank you in advance
You can set padding instead of margin and you will have the same result.

TextView without any default padding [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
I want textView without any default padding while increasing size of textView
I want to remove default padding on TextView. When i increase the size of TextView then its padding size increases automatically. even i set background of text View as "#null". i just want to show only text without any padding. my View looks like this first images and i want to show like second images.
This First link shows View is displaying.
http://www.imageurlhost.com/images/487vskfx1aj01f9e9g40.png
This second link show Layout view that i want to show without giving any -margin
http://www.imageurlhost.com/images/ijuyxpcub1oqy1w66h.png
It's called font padding. You can disable it with mTextView.setIncludeFontPadding(false); or xml attribute android:includeFontPadding="false"
You can remove the padding from xml by setting the padding to 0dp
Try something like this:
<TextView
android:padding="0dp"
...
</TextView>
Note that if you do that, you can't use gravity anymore, since that is working using padding.
If you want to remove only top and bottom padding, you can set paddingBottom and paddingTop to 0dp and work with the side padding.
Cheers,
Arkde

Increase height of TextView on runtime

I have a TextView and I want to increase its height on runtime.
I have used android:layout_height="wrap_content" but it did not gave me the desired result.
I'm using a Relative Layout.
i get text through edittext and i want to set it on textview.
when i do this it shows only one line, and when i click on edittext it get expanded and full message is shown.
Add in Oncreate method of your
Activity class,
((TextView)
findViewById(R.id.YOURTEXTVIEWIDHERE)).setHeight(IntegerValuePixels);
hard to tell without more details - but do you really need to change it on runtime? because obviously you're not happy with the height at startup.
have you thought about using android:layout_height="fill_parent", eventually in combination with the android:minHeight attribute of other components?

Categories

Resources