Android RemoteViews,如何在小部件内设置 ImageView 的 ScaleType?

编程入门 行业动态 更新时间:2024-10-21 09:40:20
本文介绍了Android RemoteViews,如何在小部件内设置 ImageView 的 ScaleType?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在开发一个在右侧带有图像的小部件,用户可以在其中一个设置屏幕中进行选择.然后可以使用 ImageView.setScaleType("CENTER") 从用户设置图像.那个有效.然后将图像的 URL 作为 URL 存储在首选项中,也作为位图的 Base64 编码字符串(因为我想缩小图像并且用户可以在设置中旋转它)

I am developing a widget with an image on the rigth side, which can be choosen by the user in one of the settings screen. The image can then be set from the user with the ImageView.setScaleType("CENTER"). That works. The URL of the image is then stored in the preferences as URL, and also as Base64 encoded String of the Bitmap (cause I want to shrink the image and the user can rotate it in the settings)

在小部件中,我加载图像.这很好用.使用 URI 和位图.ImageView 的 ScaleType 在 Layout 中也设置为固定值,也可以.

In the widget, I load the image. That works fine. With the URI and with the Bitmap too. The ScaleType of the ImageView is set as well to a fixed value in the Layout, works too.

但是如何以编程方式在小部件中定义 ImageView 的 ScaleType?因为我想将 ScaleType 设置为用户在设置中选择的值.使用 RemoteViews,我们无法获取 ImageView...

我试过了:

myRemoteViews.setString(R.id.myImage, "setScaleType", "CENTER");

myRemoteViews.setString(R.id.myImage, "setScaleType", "CENTER");

<小时>

日志文件说:ImageView 无法使用 setScaleType 函数.


The logfile says: The function setScaleType is not possible for ImageView.

有人知道如何在 AppWidget 中进行这个定义吗?

Does someone know how to make this definition inside the AppWidget?

推荐答案

您可以使用此段以编程方式设置 Image View 的缩放类型..

You can use this segment to set scale type for Image View programatically..

 imgview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

希望有帮助...

这篇关于Android RemoteViews,如何在小部件内设置 ImageView 的 ScaleType?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 03:01:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128987.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:部件   如何在   RemoteViews   Android   ImageView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!