One of my actions on the project, including the long text written in the string.xml file, I add some images from the resource to textview, because after each phrase there is an image, then the next text phrase, then the image, etc.
I get these images from a string using this code:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView htmlTextView = (TextView) findViewById(R.id.day_tv); htmlTextView.setText(Html.fromHtml(getString(R.string.day), new ImageGetter(), null)); } private class ImageGetter implements Html.ImageGetter { public Drawable getDrawable(String source) { int id = 0; if (source.equals("image1.jpg")) { id = R.drawable.a; } else if (source.equals("image2.jpg")) { id = R.drawable.b; } else if (source.equals("image3.jpg")) { id = R.drawable.c; } else if (source.equals("image4.jpg")) { id = R.drawable.d; } else if (source.equals("image5.jpg")) { id = R.drawable.e; } Drawable d = getResources().getDrawable(id); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); return d; } }; }
and writing the html img tag in string.xml as:
<img src="image1.jpg">
I want to be able to customize each image by changing its width and height or referring to a drawing style to add a border around the images, for example.
I tried using the varying width and height of the foe code:
<img src="image1.jpg" width="100" height="150">
but that will not work.
Any advice to achieve this will be appreciated, thanks.
source share