I want to set the text size in my app. 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). But the problem is some devices in emulator have different sizes but having same dpi. So I am little confuse how to write different text sizes in dimens depending upon screen sizes not on dpi value. And how its work?
I think depending on device size android pick layout and then depending on dpi its choose values. Is it correct or not?
Edit-
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. I want size of text big on large screen although they belong mdpi.
Yes it is correct. Depending on the device screen size and specification, android automatically loads the desired layout and all its elements and fonts.
style="#android:style/TextAppearance.DeviceDefault.Medium"
no need to create all layouts, just see this example it is working for me
Note :textviewtwo.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimension(R.dimen.textsize));
http://polamreddyn.blogspot.in/2014/01/adjust-text-size-in-all-android-devices.html
Related
app screen on galaxy s4 it skip right and bottom part because of small size mobile
I am having problem in Design different screen size.
how should all 5 categories will support most of the mobile screen?
my Android App Design Normal screen works on 5 inch mobile screen where as for 4 inch screen it skip below content.
for example it work nice on samsang galaxy s4 (5 inch) also on nexus 4.
but as shown in image when i see on nexus S(4 inch screen) it skip some bottom and right part .it cannot hold full layout mostly top and left part it display.
how to design normal screen which support these screen size changes?
is it compulsory to use wrap_content or Match_parent or fill_parent only to get rid of it.
for that also i am confused of specifying image size for different screen size in drawable.
also is normal screen be of different density such as hdpi,mdpi,ldpi etc.
how to solve this issue is it sufficient to use dp and sp?
and last one, in Android Studio we design 5 types of layout.for example activity_channel_list.xml(small). etc( for normal,large,xLarge).what last just activity_channel_list.xml represent.is it like if not any layout is selected.this will be selected by default.
Thanks in advance.
If you want to design layouts for different screens then make folders accordingly link
layout-mdpi
layout-hdpi
layout-xhdpi
layout-xxhdpi
If you don't want create different layout for different screens then simply use dimension file and create different dimens in that like
values-hdpi (dimen)
values-xhdpi (dimen)
values-xxhdpi (dimen)
and the difference between dp and sp is, we use dp for give dimensions to the image, and for size purpose and sp is use for define text size
the screen size id efferent and you cant make a layout for every one you need to try categorize the screen with layout selector
if you use sp for text the text size will change when user change the android font size and it is better to use dp for text
and last Question is like first one you need to categorize layout for size and density normaly
How should all 5 categories will support most of the mobile screen?
Take care if these following aspects while designing layouts:
1.Always design layouts inside scrollview, so that for smaller screens user will be able to view complete layout by scrolling
2.Use sp for text Sizes
3.Use dip(density independent pixels) for all widget sizes, usage of dip makes the size of widget according to mobile profile(like 240*320 may use ldpi so according widget size will change)
4.All the icons you are using you need to generate for all profiles(ldpi,hdpi,xxhdpi,xhdpi) and store in drawable-xxxx folder
If you dont want to generate images for all profiles you can use font icons (like font awesome,iconmoon)
font icons appear according to screen sizes.
5.Last but not least, avoid using hardcoded margins between widgets use attributes like gravity,center_in_parent etc.. so that screen looks uniform in all devices.
I have 3 devices
1) galaxy nexus 720*1280 (xhdpi, normal size category )
2) motorola 480*854 (hdpi, normal size category)
3) htc 320*480 (mdpi, normal size category)
I have my xmls in my layout folder. In my xmls I need to fix sizes to my textviews,Edittext(it will expand with the text entering).
Because of this,I am getting problems in my motorolo,htc devices.I cannot able to prepare different layouts because these 3 devices are comes under layout-normal(layout).
I have Textviews in Rectangular background,with the text increases rect box is getting expanded.
Is there any option to prepare different layouts for each of the devices.
please suggest
Thanks
You can target densities by using a layout folder like layout-mdpi, layout-hdpi and a layout-xhdpi. Why would you want to do this? using dips for everything will be fine.
Edit: suggestions based on the comments you gave:
by using a value like 200dp, the boxes on all devices kinda have the same size. Not in pixels but in actual size on the screen. This is what dips (the dp unit) is made for.
The screens are supposed to look kinda the same on the different device sizes. Read the description on http://developer.android.com/guide/practices/screens_support.html especially the section named "Density independence".
After reading that and if you still really, and I strongly suggest you don't do that, want them to look different on different screen sizes do this.
In your layout xml define the width as android:layout_width="#dimen/the_width"
In the folder values, create a file values.xml. In there define a dimension like this <dimen name="the_width">200dp</dimen>. 200dp is an example and will be the default value.
Override this value in the values-hdpi, values-xhdpi and/or values-mdpi folder, by creating the same values.xml, but with a different value for the_width.
This will make the edittext have a different size on different screen sizes.
I know this has been answered in other questions, but nothing is working for me. I have a text view where I want the text to appear the same size in a variety of density/screen size combinations. I have tried specifying
android:textSize="30dp"
and
android:textSize="30sp"
and have also used
TextView text = (TextView) findViewById(R.id.text);
text.setTextSize(30 * (getResources().getDisplayMetrics().density));
30 is my font size *****
the text doesn't scale properly. It becomes way too small at lower densities and as screen size increases. Are there additional techniques I can use to scale my font?
create layout-large, layout-small, layout-xlarge etc.. versions of your layout xml file.
You can set the size differently in each so that the font will look right across a variety of screen sizes.
After years of constantly having everything slightly off on different devices, I recently discovered that the inches and cm measurements for dimensions are literally that.
So even on devices where 160dp isn't quite an inch, specifying 1inch will give exactly that, on everything, even if they have a custom scaled ROM.
I now specify anything I want very tight control over with these.
If you just want to have separate font sizes for separate screens, you can create dimens in your value.xml for sw600dp and sw720dp folder too and put different values there. You don't need to create separate xml layout for each, if you just need to change font sizes.
I develop app for android. I test it on many devices but I have problem with 8" tablet with 800x600 resolution. The text field is out of the screen. I have 4 folders with layouts: "layout", "layout-small", "layout-large", "layout-xlarge". How can I make proper layout for this tablet?
Make four layout folders, one for each size bucket. Put static text in each layout that says which one it is. Run the app. Read what gets displayed.
Refer Using new size qualifiers, where we have more control over the screen sizes.
We can set Qualifier values like sw600dp, w800dp, etc
I am developing for android and my code runs perfect on nexus or any 3.7 inch device.
If I run it on tablet (7 or 10.1 inch) then the fonts and buttons are very small and the spacing is way too big.
If I run it on 2.7 QVGA then the buttons are too big and overlap.
I am using dp and sp all over the layout so I am surprised it didn't adjust according to different screen size/density.
Does that mean that I have to wrte the same XML layout in 3 layout folders (large, medium and small) and put my drawable in 3 different density folders?
Or am I amissing something here. Yes I read the "Supporting multiple screen" document and it just loses me with the details (but I did follow the tips of using dp and sp). I am looking for more of a summary/general approach answer.
dp and sp adjusts according to screen density. Therefore, a screen with 500 dpi and 4000 dpi but with the same SCREEN DIMENTIONS will looks the same.
If they have different screen sizes, it won't fit as you want. If you want to support multiple screen sizes, you'd have to use weights or percentages.
The key is that dp = device independent pixel and it only adjusts according to density, not screen size.
In the most cases if you don't make a tablet app, you don't need to make more than one XML layout for different densities/sizes. All you must do is define dimensions with DP and SP as you said.
But is necessary to provide different images in the drawable folder to show one or other in function on screen size/density.
If you put all images in drawable folder (without specify hdi,ldi or mdi) Android will try to adjust the images but not always works fine.
Hope it helps.