hello, how do I calculate the font size of a TextView so that always
occupy a certain percentage of the screen? now I spit it out:
-------8<---------------8<---------
.....
densityNormal = Float.parseFloat("1.0");
densitySub = Float.parseFloat("0.75");
densityIper = Float.parseFloat("1.5");
densityExtra = Float.parseFloat("2.0");
.....
textviewSample.setTextSize(getHeightPercentage(context,30));
.....
private float getHeightPercentage(Context context, int percentage) {
    if (percentage > 0 && percentage < 100) {

        float appHeight = context.getApplicationContext().getResources()
                .getDisplayMetrics().heightPixels;

        float appSPDensity = context.getApplicationContext().getResources()
                .getDisplayMetrics().scaledDensity;

        if (Float.compare(appSPDensity, densitySub) == 0) {
            appHeight = appHeight + ((appHeight * 25) / 100);
        //<---
        } else if (Float.compare(appSPDensity, densityIper) == 0) {
            appHeight = ((appHeight * 50) / 100) - appHeight;
          //<---
        } else if (Float.compare(appSPDensity, densityExtra) == 0) {
            appHeight = ((appHeight * 200) / 100) - appHeight;
         //<---
        }

        return new Float((appHeight * percentage) / 100);
    } else
        return -1;
}
-------8<---------------8<---------
but I can not integrate the different density of the screen,have you
any suggestions?8y3

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to