简体   繁体   English

如何在TextView Android Java中将图像调整为相同宽度

[英]how to fit image to the same width inside TextView android java

i have an image stored in database as blob and i restore it as Bitmap Image and put it inside a textview here is my code 我有一个图像作为blob存储在数据库中,并将其还原为位图图像,并将其放在textview中,这是我的代码

byte[]q_img=cur.getBlob(10);
Drawable qDrawable = new BitmapDrawable(ctx.getResources(),BitmapFactory.decodeByteArray(q_img,0,q_img.length));
question.setCompoundDrawablesWithIntrinsicBounds(null,null,qDrawable,null);

this code works perfectly and show image inside textview but the problem is in some images have width larger than width of TextView and get overflow of width so how i can fit the width of image to the same width of textview 此代码可以正常工作并在textview中显示图像,但问题是某些图像的宽度大于TextView的宽度,并且出现宽度溢出,因此我如何将图像的宽度调整为与textview相同的宽度

Try this and see if it works. 试试这个,看看是否可行。

set layout_width="wrap_content" in your XML file XML文件中设置layout_width="wrap_content"

or TextView txt= new TextView(context); txt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); TextView txt= new TextView(context); txt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); TextView txt= new TextView(context); txt.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); using java 使用java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM