1

I'm trying to show content (text and images) in a TextView. It works very well by this method: Android HTML ImageGetter as AsyncTask

But sometime images are larger then width of screen.
How can I force images to use percentage width?

EDIT: The percent width value is not important, I just want to see images with equal scale on each screen size.

Community
  • 1
  • 1
lordjancso
  • 135
  • 2
  • 2
  • 10

2 Answers2

0

You can't use percentage width. Accepted units are (quoted from the Android documentation):

Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), mm (millimeters).

I think it is possible to set the width programmatically based on screen size, though I'm not aware of the calculations needed.

Piovezan
  • 3,215
  • 1
  • 28
  • 45
0

The only way to do that is programmatically.
To change the Bitmap size see this.
To get sreen size see this.
To get View size you must use in post method:

yourView.post(new Runnable() {
    @Override
    public void run() {
        int h = yourView.getHeight();
        int w = yourView.getWidth();
    }
});
Community
  • 1
  • 1
NickF
  • 5,637
  • 12
  • 44
  • 75