Setting programmatically the pixel size of a remote ImageVIew?

女生的网名这么多〃 提交于 2019-12-25 05:16:40

问题


Let's say that I have a layout that contains

<ImageView
        android:id="@+id/my_id"
        android:layout_width="123px"
        android:layout_height="345px"
        android:padding="0dip"
        android:scaleType="fitXY" />

which is used in an AppWidget and is set via a RemoteViews. How can I programmatically set the width and height in pixels (overriding the 123 and 345 in the above xml)?

(motivation: this image view shows a dynamic png file that is set at runtime via a file URL. If the layout_width and layout_height above are set to wrap_content, the image is displayed scaled down the the device's density(). Setting the exact width and height in pixels solves the problem but the file size changes and I don't know how to set it programmatically).


回答1:


You can do it in a different way. Put your ImageView in a LinerLayout and set layout_width and layout_height of ImageView to "fill_parent". Then change LinearLayout's width and height.

I assume you know about app widgets size rules.



来源:https://stackoverflow.com/questions/9745227/setting-programmatically-the-pixel-size-of-a-remote-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!