Android widget Textview size for smaller screens - android

In my widget layout file, I have set textview text sizes and all my content fits inside the widget. When I launched on a smaller phone (320x480) a lot of the text was cut off and was not visible on the widget. How can I account for smaller phone sizes and define smaller textview sizes?

You should use dimens to set textsize based on phone's screensize.
Look in above image I made 4 dimens for different screen sizes.
In dimens(w820dp) I wrote following code.
<resources>
<!--include 7" and 10" devices -->
<dimen name="activity_horizontal_margin">64dp</dimen>
<dimen name="item_image_size">60dp</dimen>
</resources>
While in dimens.xml(sw600dp) I wrote following code as per requirements.
<resources>
<!-- For 7” tablets (600dp wide and bigger) -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="item_image_size">54dp</dimen>
</resources>

Refer this answer and
add
android:maxWidth="size" //size- the number more than 1
this in your textview layout

Related

How to make the android app fit all Screen Sizes?

I have a customized application , i install the app for select users . My application has separate drawable for each sizes (no problems with the drawables) , but my textViews and other content sizes does not change as per screen size . i have dimens values and i use only these 3 values across my 60 layouts, but Each time i install the app in client device, i change to values in dimens.xml according to the device inches and then build multiple apks for multiple screen size.
How do i solve this problem and make app fit all screen sizes ?
My dimens.xml
< // screen 6 inch <dimen name="radio_button_text_size" tools:ignore="MissingDefaultResource">13dp</dimen>
<dimen name="title_size" tools:ignore="MissingDefaultResource">13dp</dimen>
<dimen name="value_size" tools:ignore="MissingDefaultResource">15dp</dimen>
-->```
"'//screen 6+ inches
<dimen name="radio_button_text_size" tools:ignore="MissingDefaultResource">15dp</dimen>
<dimen name="title_size" tools:ignore="MissingDefaultResource">17dp</dimen>
<dimen name="value_size" tools:ignore="MissingDefaultResource">18dp</dimen>
"'
<!-- // screen 5inch
<dimen name="radio_button_text_size" tools:ignore="MissingDefaultResource">7dp</dimen>
<dimen name="title_size" tools:ignore="MissingDefaultResource">9dp</dimen>
<dimen name="value_size" tools:ignore="MissingDefaultResource">11dp</dimen>
-->
This happened to me as well a while back. I'm assuming you're using padding to position your views. Instead, you're gonna want to use a constraint layout and then use "horizontal bias" and "vertical bias" (the little scroll bars under the "Constraint Layout" section of the design view) to position your views. This will look the same on most screen sizes. Hope this helps!

Issues with font sizes on different dpis

I specify all font sizes in sp. The text looks good on several devices including Nexus 7, Galaxy S4 mini etc. However, on Galaxy S 3, the font is too large. Is this because the DPI of the S3 is so much more? If so, how do I adjust for this so that fonts display at relatively similar sizes?
DP/SP seems to be working properly. The larger font sizes I got was because of setting text sizes programmatically, using resource values which were already returned scaled - so essentially fonts were being double scaled. This could have been prevented by proper documentation by Android.
On my project i use different "dimens.xml" file for every type of density folder, for example:
values-mdpi
values-hdpi
values-xhdpi
dimens.xml has:
<!-- Text dimension for activity album preview -->
<dimen name="text_album_title">20sp</dimen>
<dimen name="text_album_author">18sp</dimen>
<dimen name="text_album_info">13sp</dimen>
<!-- Text dimension for row -->
<dimen name="text_track_title">16sp</dimen>
<dimen name="text_track_length">14sp</dimen>
And this is different for every file in folder. Is up to you to decide the size, you will see the difference between each dimension by using a layout with a TextView. Give it a try.
EDIT
I was totally wrong on this subject, thanks to Runloop and 323go.

android dimens value for different resolution devices

I want setup different dimen-values for different resolution(dp) devices, how ?
just in my dimens.xml
<resources>
<!-- for 1280x720 dp ,Default screen margins, per the Android Design guidelines. -->
<dimen name="image_thumbnail_size">200dp</dimen>
<dimen name="image_thumbnail_spacing">2dp</dimen>
<dimen name="image_detail_pager_margin">160dp</dimen>
<dimen name="activity_horizontal_margin">80dp</dimen>
<dimen name="activity_vertical_margin">100dp</dimen>
<!-- for 640x360 dp -->
<!--
<dimen name="image_thumbnail_size">100dp</dimen>
<dimen name="image_thumbnail_spacing">2dp</dimen>
<dimen name="image_detail_pager_margin">80dp</dimen>
<dimen name="activity_horizontal_margin">40dp</dimen>
<dimen name="activity_vertical_margin">30dp</dimen>
-->
add:
I have two devices, the resolution is 1280x720 ,but my phone dp is 640x360 , and another is 1280x720
Create seperate values folders, each with a different suffex. Some examples:
values-normal (for phone versions)
values-large (for 7" tablets)
values-xlarge (for large tablets)
Place a dimensions.xml file in each of these folders, in each one, specify different values for each variable.
Hope this helps.
Sorry to get this to you late but you can use the same folder combinations that you use for drawables with the values folder. Here is an example
values-ldpi/dimens.xml
values-hdpi/dimens.xml
values-xhdpi/dimens.xml

Android weight with margins and paddings

I need to be able to use relative sizes for paddings - to be bigger or smaller depending on the device's resolution and dpi.
For example, if my view is wide 100px, I'd like to have 10px padding left and 10px padding right.
But, if it runs on a higher density screen, and it is say 250px, I need the left and right padding to be both 25pixels each.
Hardcoding pixels or dp doesn't seem reasonable, also I prefer to avoid code-behind scaling logic if I can get away with it. I also prefer NOT to use any additional weighted empty views to gain the same effect. Not sure how I can simulate padding with it either way.
Is there a way to do this from the xml? Or do I have to scale them based on the device resolution/dpi from the code behind?
It's not really "relative sizes for paddings" but I think using an Android dimension value defined in XML will do what you want. It's hard to guess from your question as you want to avoid "hardcoding pixels" but also "do this from the xml" ;)
The link above gives this example;
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textview_height">25dp</dimen>
<dimen name="textview_width">150dp</dimen>
<dimen name="ball_radius">30dp</dimen>
<dimen name="font_size">16sp</dimen>
</resources>
Then;
<TextView
android:layout_height="#dimen/textview_height"
android:layout_width="#dimen/textview_width"
android:textSize="#dimen/font_size"/>
The Android SDK itself uses this approach;
In e.g. values/dimens.xml
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
values-sw600dp/dimens.xml
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw600dp devices (e.g. 7" tablets) here.
-->
</resources>
You can target values-FOO at API levels, screen sizes, portrait vs landscape, combinations of the above "and more" when you are providing resources by using "Configuration qualifier names".

How to resize webview objects/texts depending on screensize

I am creating an app that will be used for all screen sizes.. I have different layouts for small, normal, large, and x-large.. However, I also want my webview to adjust its sizes (text/images) depending on the size of the screen. I tried researching for viewport and values/dimens.xml but had no luck..Here is dimens.xml but I do not know how to apply it:
(This is for xlarge)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="body_padding_large"> 20dp </dimen>
<dimen name="text_size_xlarge"> 32sp </dimen>
<dimen name="speaker_image_size"> 64dp </dimen>
</resources>

Categories

Resources