Bigger menus for bigger screens - android

I am setting my mobile app to work in tablets, one of the many things that need to be tweaked is the fon t size of menus which in an 10" screen are too small. So I'm looking for a global variable that change that font size like you can do with textViews and similar things with
<dimen name="size_font_view_tex">21sp</dimen>
inside dimens-wXXXdp/dimens.xml
Anybody know the name (if it is) of the dimen resource that changes the size of menus?
Bonus: List of all dimen resources

You have to use the different layouts for different size of screen.As you stated the 10" screen you have to make the folder layout-large in your res folder and make the layout according to need. Hope this will help you.

form How to set text size of textview dynamically for different screens
You should use the resource folders such as
values-ldpi
values-mdpi
values-hdpi
And write the text size in 'dimensions.xml' file for each range.
And in the java code you can set the text size with
textView.setTextSize(getResources().getDimension(R.dimen.textsize));
Sample dimensions.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textsize">15sp</dimen>
</resources>

When you create a new layout with right click, you can manage this creation with a "available qualifers".
Here for size, keep the qualifer size and set the screen size that you want.
For example you can set x-large to create a tablet layout for the same screen that you already created before.
more explain : https://developer.android.com/guide/practices/screens_support.html

Related

Why is there a layout preview difference between Pixel and Pixel 2 in Android Studio even though they have same screen size and pixel density

I have been trying to understand why these two devices even though having same screen size and pixel density behave differently.
Please Note: The Font size and Display size are set to "Default" on both the devices.
EDIT 1: I have created the following folders in the layout folder.
layout-hdpi
layout-xhdpi
layout-xxhdpi
layout-xxxhdpi
Each folder has the activity's layout with the dimension and image size fixed. My point is, if the two mobiles are using xxhdpi layouts or the Google Pixel is using xxxhdpi and Google Pixel 2 is using xxhdpi?
I think it depends on DPI of your phone. Two phones may have different dpi. You can change dpi if phone is rooted. I dont know if stock supports.
Please Note: The Font size and Display size are set to "Default" on both the devices.
No , You have to using dimens.xml for different devices of android for Example see Below structure :
res/values/dimens.xml
res/values-small/dimens.xml
res/values-normal/dimens.xml
res/values-large/dimens.xml
res/values-xlarge/dimens.xml
dimens.xml file contains
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">18sp</dimen>
</resources>
In Textview add this
android:textSize="#dimen/text_size"

Size of textview in different screens Android

I'm getting sick to find the best away to put the same scale for textView's in different screens density and resolution.
I tried:
Create different folders, for different density and put "dimensions". Example, folder values-xhdpi and dimensions.xml, values-ldpi and dimensions.xml too. On my code, programmatically i get textView.setTextSize(getResources().getDimensions(R.id.myDimension);
In xml, 20sp
like example above, but put this textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensions(R.id.myDimension);
Add textAppearence , like textView.setTextAppearance(this,android.R.style.TextAppearance_Large);
But all examples, i got what i wasnt expected, because got texts biggers in biggers density. like in image below
this happen except if i change my dimension in appropriate xml. But, what structure should i follow?
For an example, in drawbles, people reccomend to use scale like 3:4:6:8, but here i didnt follow a structre.
What are the best pratices ? What people normally do..?
What i want? this..
You have to use a pixel independent unit for your text size. Make dimensions with sp unit and load them programmatically.
For supporting multiple screens take a look in android documentation
For the sp unit says :
Similarly, you should prefer the sp (scale-independent pixel) to define text sizes.
The sp scale factor depends on a user setting and the system scales the size
the same as it does for dp.
In other words you have two
You have to declare in values file dimension elements. If you don't like the result and you want to declare for each screen category specific text size you have to do the following :
You can create a values folder for each dpi. For instance , the folder name can be : values-hdpi , values-xhdpi etc.
Inside the values file you can place a dimens.xml file in which you will declare as
<resources>
<dimen name="small_font_size"=10sp></dimen>
<dimen name="large_font_size"=20sp></dimen>
</resources>
It's up to you. You can create different dimensions files for different screen sizes. For example:
values-sw720dp 10.1” tablet 1280x800 mdpi and bigger
values-sw600dp 7.0” tablet 1024x600 mdpi and bigger
values-sw480dp 5.4” 480x854 mdpi and bigger
And take the value in sp for your TextView from your dimensions files.

Font size of text

I have created different layouts (layout, layout-small, layout-normal, layout-large, layout-xlarge) and for values (values, values-ldpi, values-mdpi, values-nodpi, values-hdpi, values-xhdpi). I have one activity in my app to show text. I have scroll on text. And I set the values of text size in values-mdpi. But when I run my app on emulator 3.2"QVGA(ADP2)(320 x 480:mdpi) scroll on text work. But when I run my app on emulator 5.1"WVGA(480 x 800:mdpi) all text on half screen and the size of text is small. I think android picking layout depending upon size and text size depending upon values-mdpi. I want size of text big on large screen although they belong mdpi.
My whole app is in portrait mode. And also same case with ldpi and hdpi. Please provide general solution.
Create folder like values-mdpi , values-w360dp-mdpi in res folder.
create dimens.xml on both folder.
and paste it below code in values-mdpi dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textsize">14sp</dimen>
</resources>
and paste it below code in values-w360dp-mdpi dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textsize">18sp</dimen>
</resources>
then apply text size on your activity
android:textSize="#dimen/textsize"
you are using only portrait version, if you are using same structure of design for all devices you don't need to add four different layout for each pixel density.
create android values folders that supports different screen sizes.
Here first folder for 7inch android devices that have ANDROID version 3.1 or less. second one is for 7inch devices that have android version greater than 3.1.
naming convention sw600 means smallest width of 600. so this folder works for width size 600 to 720. So create values-sw480dp and values-sw320 add values to dimens.xml file.
Android runtime automatically picks values from appropriate folder.
Just create layout folders like layout, layout-small, layout-large, layout-xlarge then create values folders like values, values-ldpi, values-mdpi, values-hdpi, values-xhdpi. Then you can create values folder depending upon height or width and belongs to ldpi or mdpi i.e values-w360dp-mdpi or values-h600dp-mdpi. Then android automatically picks layout depending upon screen size and values on depending height or width.
Try to add this in your AndroidManifest.xml
<supports-screens android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true"/>
Just instead yourvalues (values, values-ldpi, values-mdpi, values-nodpi, values-hdpi, values-xhdpi),
which are specifying the text font sizes for each density.
Use text size specification based on screen size, like this:values (values, values-small, values-normal, values-large, values-xlarge)
Alternatively to obtain better results for various devices you can combine density with screen size, like this:values-normal-mdpi
That's all
Try like this
STEP : 1
first in res folder => values => dimensions.xml=> create dimensions.xml file to values folder in that create like below code depending on textsize
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textsize">8sp</dimen>
<dimen name="text">10sp</dimen>
<dimen name="comments">7sp</dimen>
</resources>
STEP : 2
in java file write this line
TextView textviewtwo = (TextView)findViewById(R.id.sponsertwo_txt);
textviewtwo.setText("brought to you by");
textviewtwo.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimension(R.dimen.textsize));
// in place of textsize use text and comments what ever we want depending on size. use like text size adjust automatically in all devices
Actually you don't need to create all these layout directories to handle text size. Just stick with the normal one (layout) and create different values directories with different text size for each resolution you want to support. so you have to add text size in other values directories.
At run-time Android will pick the correct text size.
Use this code, it works based on screen size:
Display display = getWindowManager().getDefaultDisplay();
int displayWidth = display.getWidth();
yourTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX,(float)(displayWidth * 6/100));

Android font size on different screens

I want to use different font size for different screen sizes.
I read about this many articles, but I'm not sure about usage. Is correct to use different dimens resource file for different screen dimensions like code below:
res/values/dimens.xml
res/values-small/dimens.xml
res/values-normal/dimens.xml
res/values-xlarge/dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">18sp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">24sp</dimen>
</resources>
...
I also read that correct way is to use sp for font size, but this doesn't fit font in different screen dimensions as I expect.
If there, what are the disadvantages of using different dimens for every size?
Thanks
The best way is to create different layout resources for each of the screens you wish to support. Place each of the layouts in a separate folder that designates the width of the screen. For example, normal sized layouts go in your res/layout folder, and a layout resource for a 7 inch tablet (600 pixel width) would go in the res/layout-sw600dp folder. Make the resource names identical, but adjust your font sizes accordingly.
#up Not, it isn't good way.
#topic You can gets width & height of screen (and w&h of View). Next, you can set font, for example 2% of width screen. If you have content 1260x720, 0.02*1260=24,6 px (you can use also (int)24.6 to convert double to int)
I do something very similar and it's worked fine for me. Some people put the values in the various layouts such as Fietser suggested, but if all of your layouts end up being the exact same except for the font size, your approach is better. That way you can have a single layout and only modify the font sizes. But sometimes you might have changes in the actual layout xml, so then it's probably a wash between the two approaches.

How to use different font sizes on 480x800 and 1280x760 screen?

I have read Different font sizes for different screen sizes, but I found that is not working well for me.
I created a values-hdpi to define styles, but I found both 480x800 and 1280x760 use it -- the screen size is so different!
Is there any way to let 480x800 screen use one font size and 1280x760 use another one?
Yes.
Create screen-specific dimensions files, like this,
values-sw720dp/dimens.xml
values-sw600dp/dimens.xml
values/dimens.xml
The first is for 10" tablets, the second is for 7" tablet, and the last is for phones. If that doesn't give you the gradations you want, read this page to find out other ways of targeting different screens.
In those files, define a dimension,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen
name="my_size">40sp</dimen>
</resources>
adjust the dimension value in each of the dimens.xml files to your liking.
Now in your layout,
<TextView ...
android:textSize="#dimen/my_size"/>

Categories

Resources