imageview 相关问题

显示任意图像或可绘制图形的Android小部件,例如图标。

有什么想法为什么我的 Android Studio 应用程序在为 ImageView 设置可绘制对象时随机崩溃吗?

我确信这是一个徒劳的问题。但我编写了多个应用程序,每个应用程序在更新图像时都会随机崩溃。 我使用 findViewById(..).setBackgroundResource(..) 方法。 兴趣...

回答 1 投票 0

android如何将SVG加载到imageView中

我尝试将SVG路径加载到imageView中,但我不能 例如,我有 SVG 路径作为字符串 ” 我尝试将 SVG 路径加载到 imageView 中,但我不能 例如,我有 SVG 路径作为字符串 "<svg width="35" height="35" viewBox="0 0 35 35" fill="none" xmlns="http://www.w3.org/2000/svg"> <path fill-rule="evenodd" clip-rule="evenodd" d="M6.48918 13.6276C6.70383 13.0193 7.37699 12.6841 7.98482 12.8979C8.59265 13.1117 8.89133 13.7854 8.67782 14.3938C8.33132 15.3794 8.16683 16.4263 8.16683 17.4949C8.16683 18.572 8.36283 19.64 8.71399 20.6325C8.92864 21.2403 8.59148 21.8766 7.98482 22.0919C7.37699 22.3072 6.70501 22.0065 6.48918 21.3988C6.0505 20.1567 5.8335 18.8386 5.8335 17.4949C5.8335 16.1619 6.05634 14.861 6.48918 13.6276ZM26.3225 14.4302C26.1125 13.8209 26.4438 13.1817 27.0528 12.9709C27.6606 12.76 28.3 13.0547 28.5111 13.6641C28.9311 14.8823 29.1668 16.1806 29.1668 17.4949C29.1668 18.8454 28.9545 20.1511 28.5111 21.3988C28.2941 22.0061 27.6233 22.3448 27.0155 22.1285C26.4088 21.912 26.0705 21.24 26.2863 20.6325C26.641 19.6356 26.8335 18.5775 26.8335 17.4949C26.8335 16.4413 26.6597 15.4037 26.3225 14.4302ZM17.5002 24.4999C18.1445 24.4999 18.6668 23.9772 18.6668 23.3324C18.6668 22.6876 18.1445 22.1649 17.5002 22.1649C16.8558 22.1649 16.3335 22.6876 16.3335 23.3324C16.3335 23.9772 16.8558 24.4999 17.5002 24.4999Z" fill="#88B8E9"/> <path fill-rule="evenodd" clip-rule="evenodd" d="M10.5 11.0833C10.5 8.82817 12.3282 7 14.5833 7H20.4167C22.6718 7 24.5 8.82817 24.5 11.0833V23.9167C24.5 26.1718 22.6718 28 20.4167 28H14.5833C12.3282 28 10.5 26.1718 10.5 23.9167V11.0833ZM17.5 24.5C18.1443 24.5 18.6667 23.9777 18.6667 23.3333C18.6667 22.689 18.1443 22.1667 17.5 22.1667C16.8557 22.1667 16.3333 22.689 16.3333 23.3333C16.3333 23.9777 16.8557 24.5 17.5 24.5Z" fill="#88B8E9"/> </svg>" 如何将此路径加载到imageView中 你好兄弟试试这个! 最好的方法是转到 res->drawable->Vector Asset -> 本地文件(SVG、PSD)->从保存位置选择 SVG 文件。 并在您的项目中使用图像 您可以使用 Glide 加载 SVG 图像并将其设置到您的 ImageView 上 有一个示例。 创建SvgDetector.java、SvgDrawableTranscoder.java、SvgModule.java、SvgSoftwareLayerSetter.java后,您可以加载 svg 文件: GenericRequestBuilder<Uri,InputStream,SVG,PictureDrawable> requestBuilder = Glide.with(context) .using(Glide.buildStreamModelLoader(Uri.class, context), InputStream.class) .from(Uri.class) .as(SVG.class) .transcode(new SvgDrawableTranscoder(), PictureDrawable.class) .sourceEncoder(new StreamEncoder()) .cacheDecoder(new FileToStreamDecoder<SVG>(new SvgDecoder())) .decoder(new SvgDecoder()) .placeholder(R.drawable.svg_image_view_placeholder) .error(R.drawable.error_image) .listener(new SvgSoftwareLayerSetter<Uri>()); Uri uri = Uri.parse(svgImageUrl); requestBuilder .diskCacheStrategy(DiskCacheStrategy.SOURCE) .load(uri) .into(imageView); 依赖关系 //AndroidSVG implementation 'com.caverock:androidsvg-aar:1.4' 代码 val str = "\"<svg width=\"35\" height=\"35\" viewBox=\"0 0 35 35\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\"> <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M6.48918 13.6276C6.70383 13.0193 7.37699 12.6841 7.98482 12.8979C8.59265 13.1117 8.89133 13.7854 8.67782 14.3938C8.33132 15.3794 8.16683 16.4263 8.16683 17.4949C8.16683 18.572 8.36283 19.64 8.71399 20.6325C8.92864 21.2403 8.59148 21.8766 7.98482 22.0919C7.37699 22.3072 6.70501 22.0065 6.48918 21.3988C6.0505 20.1567 5.8335 18.8386 5.8335 17.4949C5.8335 16.1619 6.05634 14.861 6.48918 13.6276ZM26.3225 14.4302C26.1125 13.8209 26.4438 13.1817 27.0528 12.9709C27.6606 12.76 28.3 13.0547 28.5111 13.6641C28.9311 14.8823 29.1668 16.1806 29.1668 17.4949C29.1668 18.8454 28.9545 20.1511 28.5111 21.3988C28.2941 22.0061 27.6233 22.3448 27.0155 22.1285C26.4088 21.912 26.0705 21.24 26.2863 20.6325C26.641 19.6356 26.8335 18.5775 26.8335 17.4949C26.8335 16.4413 26.6597 15.4037 26.3225 14.4302ZM17.5002 24.4999C18.1445 24.4999 18.6668 23.9772 18.6668 23.3324C18.6668 22.6876 18.1445 22.1649 17.5002 22.1649C16.8558 22.1649 16.3335 22.6876 16.3335 23.3324C16.3335 23.9772 16.8558 24.4999 17.5002 24.4999Z\" fill=\"#88B8E9\"/> <path fill-rule=\"evenodd\" clip-rule=\"evenodd\" d=\"M10.5 11.0833C10.5 8.82817 12.3282 7 14.5833 7H20.4167C22.6718 7 24.5 8.82817 24.5 11.0833V23.9167C24.5 26.1718 22.6718 28 20.4167 28H14.5833C12.3282 28 10.5 26.1718 10.5 23.9167V11.0833ZM17.5 24.5C18.1443 24.5 18.6667 23.9777 18.6667 23.3333C18.6667 22.689 18.1443 22.1667 17.5 22.1667C16.8557 22.1667 16.3333 22.689 16.3333 23.3333C16.3333 23.9777 16.8557 24.5 17.5 24.5Z\" fill=\"#88B8E9\"/> </svg>\"" val svg = SVG.getFromString(str) val drawable = PictureDrawable(svg.renderToPicture()) imageView.setImageDrawable(drawable) 您可以使用 Glide 库来实现此目的。默认情况下,Glide不支持SVG图像解码,但提供了一种使用您自己的@GlideModule附加此图像的方法。我正在使用 Glide 版本 4.16.0,并进行了一些调整。 完整示例项目 这里提供了完整的 kotlin 示例项目: https://github.com/hanscappelle/android-glide-svg-example/tree/kotlin-conversion 它基于 Glide 提供的 SVG 示例项目,但转换为 Kotlin 并在可能的情况下进行了简化。请点击此链接查看原始(非 Kotlin)示例 https://github.com/bumptech/glide/tree/v4.16.0/samples/svg 示例代码 app/build.gradle(.kts)中的依赖项和 kapt 配置 plugins { id("com.android.application") id("org.jetbrains.kotlin.android") id("org.jetbrains.kotlin.kapt") } repositories { google() mavenCentral() } dependencies { implementation("com.github.bumptech.glide:glide:4.16.0") implementation("com.caverock:androidsvg:1.4") kapt("com.github.bumptech.glide:compiler:4.16.0") } AppGlideModule 注册 SVGDecoder @GlideModule class SvgModule : AppGlideModule() { override fun registerComponents( context: Context, glide: Glide, registry: Registry ) { registry .register(SVG::class.java, PictureDrawable::class.java, SvgDrawableTranscoder()) .append(InputStream::class.java, SVG::class.java, SvgDecoder()) } // Disable manifest parsing to avoid adding similar modules twice. override fun isManifestParsingEnabled() = false } 和最小的SVGDecoder实施。请注意,在 4.12 版本的 Glide 示例中添加了尺寸处理,这会破坏图像上设置的 scaleType。 class SvgDecoder : ResourceDecoder<InputStream, SVG> { override fun handles(source: InputStream, options: Options) = true @Throws(IOException::class) override fun decode( source: InputStream, width: Int, height: Int, options: Options ): Resource<SVG>? { return try { val svg = SVG.getFromInputStream(source) SimpleResource(svg) } catch (ex: SVGParseException) { throw IOException("Cannot load SVG from stream", ex) } } } 从远程 URI 加载 SVG 图像需要在视图中使用常规 Glide 代码 val svgPath = "https://www.clker.com/cliparts/u/Z/2/b/a/6/android-toy-h.svg" val imageView: ImageView = findViewById(R.id.single_image) Glide.with(baseContext).load(svgPath).into(imageView) 也许这些图书馆可以帮助你 https://github.com/corouteam/GlideToVectorYou https://github.com/ar-android/AndroidSvgLoader https://github.com/androidbroadcast/SvgGlidePlugins

回答 5 投票 0

如何在 Android 中使用 Coil 为 imageview 绘制边框?

我正在使用“线圈”来获得圆形图像视图。我想为这个圆形图像视图绘制一个圆形边框。如何使用线圈来做到这一点? 这是我加载图像的地方: 绑定。

回答 3 投票 0

如何在Android中仅在图像的某些部分设置图像过滤器

我有一些白色背景的图像,里面有一些文字和徽标。我只想为文本和徽标设置过滤器,但不为白色背景设置过滤器。 我尝试过设置过滤器,但它只是改变了......

回答 1 投票 0

Android中如何将图标垂直对齐到textview第一行的中心

我想放置左侧图标(请参阅下图),垂直居中于 TextView 中文本的第一行。我找不到方法,我在文本视图、重力和约束上尝试了drawableLeft...

回答 2 投票 0

使用 Coil 在宽度上缩放图像并在高度上裁剪图像

我有一个具有固定高度(400dp)和可变宽度(匹配父级)的ImageView。我正在使用 Coil 从网络加载内容。 我有一些风景图像和其他肖像图像。 我是...

回答 1 投票 0

Android应用程序的后台问题

我正在使用 Android Studio 实现一个应用程序,并且我创建了一个 Activity 来选择背景。如果我使用我已经意识到的导航按钮,一切都会正常,但如果我按...

回答 1 投票 0

如何获取屏幕尺寸

所以我有一个在 LinearLayout 中定义 ImageView 的应用程序。 ImageView 和 LinearLayout 的宽度和高度被指定为“match_parent”,并且 ImageView 确实看起来是......

回答 1 投票 0

Fresco - 如何检查文件是否是 webP 动画?

我有一个webP格式的图像文件。如何以编程方式检查它是动画 webP 还是静态图像?

回答 2 投票 0

检测对 imageView 中特定 x 和 y 坐标的点击

我的桌面上有一个图像,我已使用“画图”应用程序打开该图像并获取带有 x 和 y 像素的特定位置,例如:374,207 px 但是当我将图像添加到我的 Android 应用程序并使用时...

回答 1 投票 0

Android ImageButton 和 TextView 在 Framelayout 中的索引位置

我有一排 3 个 ImageButtons 包裹在 LinearLayout 中。 然后将每个ImageButton封装在一个FrameLayout中: 我有一排 3 个 ImageButtons 包裹在 LinearLayout 中。 然后将每个ImageButton封装在一个FrameLayout中: <FrameLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1"> <ImageButton android:layout_width="wrap_content" android:layout_margin="5dp" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="centerInside" android:src="@drawable/btn1" android:background="@null" android:foreground="?android:attr/selectableItemBackground" /> <TextView android:layout_width="35dp" android:layout_height="35dp" android:text="1" android:textSize="12sp" android:textColor="#ffffff" android:padding="10dp" android:layout_gravity="top|right" android:background="@drawable/smallcircle"/> </FrameLayout> 在每个 ImageView 上,我希望在右上角有一个带有圆形背景的小数字。这工作得很好,但我无法将文本置于圆圈中心。 如果我有文字,例如15,看起来是居中的,但是当数字只有1的时候,它并不在中心。 我无法在 TextView 中使用中心,因为已经有一个布局重力将带有圆圈的数字移动到右上角。 圆圈背景: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <size android:width="35dp" android:height="35dp" /> <solid android:color="#4CAF50" /> </shape> 示例: 嗯,Android Studio 根本没有在 TextView 中自动建议我 android:gravity,但是当我手动添加它时,它就完成了。因此 android:layout_gravity 移动到正确位置,android:gravity 使文本居中。 简单:)

回答 1 投票 0

如何像 Instagram 一样点击缩放图像?科特林

我正在尝试获得与 Instagram 类似的功能,当您点击或 捏住图像,现在图像覆盖了屏幕上方的所有图像 其他观点,例如 这 我有一个包含 3 个图像的片段...

回答 1 投票 0

如何在不插入低分辨率文件的情况下显示像素化的 ImageView?

我想加载一个带有低分辨率png文件的ImageView。我想显示像素,但 ImageView 通过插值将其显示得模糊。如何避免这种情况?我想展示...

回答 1 投票 0

JavaFX。单击按钮中的线程

单击 myButton 后,运行 2 个线程。首先更改按钮图像,第二个 - 循环。我希望我的程序首先更改图像并在运行循环之后。但这不行,他们一瞬间就完蛋了。 我的...

回答 1 投票 0

如何在 android studio 中解决这个问题?我是新人,正在向udemy学习

错误:/Users/guibrilramde/MyFirstUdemy/app/src/main/res/layout/activity_main.xml:19:AAPT:错误:'@tools:sample/avatars'与属性src(attr)引用不兼容|颜色。 错误:/Users/guibrilramde/MyFirstUdemy/app/src/main/res/layout/activity_main.xml:19:AAPT:错误:“@tools:sample/avatars”与属性 src(attr)参考|颜色不兼容。 <ImageView android:id="@+id/imageExample" android:layout_width="300dp" android:layout_height="300dp" android:scaleType="fitCenter" android:src="@tools:sample/avatars" tools:srcCompat="@drawable/ab" /> 你的两条线android:src="@tools:sample/avatars"和tools:srcCompat="@drawable/ab"都决定显示哪张图片,是矛盾的。删除两者并改为写 android:src="@drawable/ab"。 ab.png 图像当然必须位于 res/drawable 文件夹中。

回答 1 投票 0

在 ImageView 中错误显示 Base64 图像

我正在开发一个 Android 项目,我需要从 API 检索 Base64 编码的图像并将其显示在 ImageView 中。但是,我遇到了图像不显示的问题

回答 1 投票 0

base64 字符串在 kotlin 中并未完全实现

我正在开发一个 Android 项目,我需要从 API 检索 Base64 编码的图像并将其显示在 ImageView 中。但是,我遇到了图像不显示的问题

回答 1 投票 0

NavDrawer 的 imageview 中的图像配置文件

我从 Parse 获取一个图像文件,基本上是用户的个人资料图像。 但现在我无法在 NavDrawer 中显示它,原因是它不是图像视图,而我得到的是图像......

回答 4 投票 0

Android:如何将整个ImageView转换为Bitmap?

我的应用程序正在显示不同比例的图像,并在(centerInside)imageView内调整大小。我需要的是从 ImageView 创建位图,包括背景(黑色......

回答 8 投票 0

为什么我的ImageView不显示图像?

尝试使用 ImageView 显示图像,但未显示。 源图像保存在drawable目录中。 尝试使用 ImageView 显示图像,但未显示。 源图像保存在drawable目录中。 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/constrainLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:visibility="visible" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.485" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:ignore="ContentDescription" tools:srcCompat="@drawable/nature"/> </androidx.constraintlayout.widget.ConstraintLayout> tools:srcCompat="@drawable/nature"用于在设计时显示图像。当您需要在运行时查看它时,您应该在您的 android:src="@drawable/nature" 中添加 ImageView: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/constrainLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerInside" android:visibility="visible" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.485" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" android:src="@drawable/nature" tools:ignore="ContentDescription" tools:srcCompat="@drawable/nature"/> </androidx.constraintlayout.widget.ConstraintLayout> 而不是使用 tools:srcCompat="@drawable/nature" 使用 android:src="@drawable/nature" 更换即可 tools:srcCompat="@drawable/nature" 由 android:src="@drawable/nature" 仅开发时间属性 -> tools: 生产级别(运行时)属性 -> android: 和 app: 运行时工具属性将被删除。所以你必须用 android:src 替换该属性。 tools:srcCompat="@drawable/nature" -> android:src="@drawable/nature"

回答 4 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.