Sunday, 15 January 2012

Android Text Sizes for different screens -



Android Text Sizes for different screens -

hey know there's lot of questions pertaining topic, need clarification.

i'm trying app closely same on device sizes. utilize 'sp' type of value "textsize", doesn't seem anything. looks big on ldpi, , hdpi screen sizes, , little on mdpi, , xxhdpi. looks how i'd on hdpi, , xhdpi screens.

i've enabled "screen support" on androidmanifest file. part i'm having problem values folders.

these have there: (i haven't made modifications of own folder structure, know of)

res -values --dimens.xml --styles.xml --strings.xml -values-v11 --styles.xml -values-v14 --styles.xml -values-w820dp --dimens.xml

do create new values folder ldpi, hdpi, xhdpi, xxhdpi, etc.? create new dimens.xml each? after that?

here's androidmanifest.xml file (application tag minimized):

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.suckatprogramming.coach" android:versioncode="1" android:versionname="1.0" > <supports-screens android:resizeable="true" android:smallscreens="true" android:normalscreens="true" android:largescreens="true" android:anydensity="true" /> <uses-sdk android:minsdkversion="14" android:targetsdkversion="19" /> <application... /> </manifest>

i'm using linearlayout if means anything. allow me know if need else me. assistance can provide.

i'm not sure whether question , can seek this.starting quite big size text in textvew , decrease , until fits..

`

public static void settextsizetofittextview(textview tv) /* * resize text size specified width , height * @param width * @param height */ int height = tv.getheight(); int width = tv.getwidth(); float mtextsize = tv.gettextsize(); charsequence text = tv.gettext(); // not resize if view not have dimensions or there no // text if (text == null || text.length() == 0 || height <= 0 || width <= 0 || mtextsize == 0) { return; } // text view's paint object textpaint textpaint = tv.getpaint(); float targettextsize = 50.0f; // required text height int textheight = gettextheight(text, textpaint, width, targettextsize); // until either fit within our text view or had reached our min // text size, incrementally seek smaller sizes while (textheight >= height) { targettextsize = targettextsize - 2; textheight = gettextheight(text, textpaint, width, targettextsize); } tv.settextsize(typedvalue.complex_unit_px, targettextsize); // textpaint.settextsize(targettextsize); } // set text size of text paint object , utilize static layout // render text off screen before measuring private static int gettextheight(charsequence source, textpaint originalpaint, int width, float textsize) { // update text paint object textpaint paint = new textpaint(originalpaint); paint.settextsize(textsize); // measure using static layout staticlayout layout = new staticlayout(source, paint, width, alignment.align_normal, 1.0f, 0.0f, false); homecoming layout.getheight(); }`

android text screens

No comments:

Post a Comment