imageview 相关问题

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

ImageView/ImageButton 中的 srcCompat 和背景有什么不同

我在RelativeLayout中有一个ImageView。 ImageView 的背景是空的,srcCompat 链接到我的可绘制文件夹中的图像。在布局预览中,一切看起来都很好,但是......

回答 3 投票 0

如何将图像缩放到顶部中心? - 安卓

我有一个图像视图作为背景。它比屏幕大。我想将其水平居中。它应该与顶部对齐。因此,原始图像的顶部应该在屏幕上看到。我可以调整大小

回答 2 投票 0

如何在android imageview中显示数据库中的图像

嗨,在我的应用程序中,我得到了该图像中的 json 响应。我想在 android imageview 中显示该图像。在该图像中,我想为 imageView 设置。 图片":"

回答 1 投票 0

将图像添加到 JavaFX TableView 列中

我是 Java 和 OOP 新手,并且在向 tableview 列添加图像时陷入困境。代码似乎有效,我可以看到学生的姓名正确,但图像未显示在列中。我收到这个电子...

回答 1 投票 0

android 库 glide 不起作用。只有这种形式的网址

我想在我的应用程序中使用glide库设置这个url照片“http://file.koreafilm.or.kr/thm/02/00/01/66/tn_DPF002814.JPG”。 Glide.with(上下文)。 加载(movieImageArray.get(

回答 3 投票 0

如何将位图放入圆角正方形中?

我正在使用 Android Studio,我希望能够从图库中拾取图像,调整其大小并通过保持正确的宽高比使其适合圆角正方形(约 300x300px)...

回答 2 投票 0

如何在 Android 中将文本屏蔽到 Imageview 中?

我一直在尝试获得如下所需的结果,但没有成功。我需要将图像视图屏蔽为文本,以便图像视图看起来像文本,但仍然作为图像视图工作,以便我可以使用缩放

回答 2 投票 0

JavaFX SceneBuilder ImageView 不工作

我需要使用 SceneBuilder 创建一个 GUI。我在界面中添加了一个 ImageView 并正确设置了图像的路径。该图像显示在 SceneBuilder 中,但是当我运行我的应用程序时,我...

回答 7 投票 0

JavaFx ImageView 不会在绑定到 VBox 的 fitWidthProperty 上调整大小

我正在尝试重新调整图像大小,使其适合(缩放)在SplitPane分配的空间中(解决方法建议:该图像在运行程序时会发生变化,它应该从...

回答 3 投票 0

大小为 [0x0] 的 null 类 com.bumptech.glide.load.engine.GlideException 加载失败:收到空模型

我正在尝试加载我在 firebase 上保存的照片,它已保存成功,但无法再次加载图像,错误是 “大小为 [0x0] 的空值加载失败 com.bumptech.glide.load 类....

回答 3 投票 0

如何在单个 ImageView 中获得不同的点击位置

我正在开发一个应用程序,我需要在其中实现热点之类的东西。热点实际上是一个具有不同部分的图像,当用户单击该图像的不同部分时...

回答 2 投票 0

不是DRM文件,无法打开

我正在寻找有关因调用而导致的重复日志打印的解决方案 BitmapFactory.decodeFile。 在我的应用程序中,我有一个 ListView 每秒由计时器重绘。 列表Vi...

回答 2 投票 0

如何在 Android Studio 中让图像随不同屏幕尺寸缩放?

在我的代码中,我的应用程序运行良好,但当我使用不同的屏幕尺寸时,我遇到了问题。按钮排列正确,但图像根本不缩放。 这是我的 XML 文件 在我的代码中,我的应用程序运行良好,但当我使用不同的屏幕尺寸时,我遇到了问题。按钮排列正确,但图像根本无法缩放。 这是我的 XML 文件 <?xml version="1.0" encoding="utf-8"?> <ScrollView 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:layout_width="wrap_content" android:layout_height="wrap_content" tools:ignore="SpeakableTextPresentCheck"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#FFC107" android:padding="40dp" tools:context=".ActivitiesActivity"> <!-- ImageView Declarations --> <ImageView android:id="@+id/alabama_music_hall_of_fame" android:layout_width="match_parent" android:layout_height="150dp" android:contentDescription="@string/alabama_music_hall_of_fame_logo" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="@id/the_boiler_room" app:srcCompat="@drawable/activity_alabama_music_hall_of_fame_card" /> <Button android:id="@+id/alabama_music_hall_of_fame_FacebookButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/alabama_music_hall_of_fame" app:layout_constraintStart_toStartOf="@id/alabama_music_hall_of_fame" app:layout_constraintEnd_toStartOf="@id/alabama_music_hall_of_fame_InstagramButton" app:layout_constraintHorizontal_chainStyle="spread_inside" /> <Button android:id="@+id/alabama_music_hall_of_fame_InstagramButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/alabama_music_hall_of_fame" app:layout_constraintStart_toEndOf="@id/alabama_music_hall_of_fame_FacebookButton" app:layout_constraintEnd_toStartOf="@id/alabama_music_hall_of_fame_WebsiteButton" /> <Button android:id="@+id/alabama_music_hall_of_fame_WebsiteButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/alabama_music_hall_of_fame" app:layout_constraintStart_toEndOf="@id/alabama_music_hall_of_fame_InstagramButton" app:layout_constraintEnd_toStartOf="@id/alabama_music_hall_of_fame_DirectionsButton" /> <Button android:id="@+id/alabama_music_hall_of_fame_DirectionsButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/alabama_music_hall_of_fame" app:layout_constraintStart_toEndOf="@id/alabama_music_hall_of_fame_WebsiteButton" app:layout_constraintEnd_toEndOf="@id/alabama_music_hall_of_fame" /> <!-- The Boiler Room ImageView --> <ImageView android:id="@+id/the_boiler_room" android:layout_width="0dp" android:layout_height="150dp" android:layout_marginTop="10dp" android:contentDescription="@string/the_boiler_room_logo" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/alabama_music_hall_of_fame" app:srcCompat="@drawable/activity_the_boiler_room" /> <!-- Buttons under The Boiler Room ImageView --> <Button android:id="@+id/the_boiler_room_FacebookButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/the_boiler_room" app:layout_constraintEnd_toStartOf="@id/the_boiler_room_InstagramButton" app:layout_constraintStart_toStartOf="@id/the_boiler_room" app:layout_constraintHorizontal_chainStyle="spread" /> <Button android:id="@+id/the_boiler_room_InstagramButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/the_boiler_room" app:layout_constraintEnd_toStartOf="@id/the_boiler_room_WebsiteButton" app:layout_constraintStart_toEndOf="@id/the_boiler_room_FacebookButton" /> <Button android:id="@+id/the_boiler_room_WebsiteButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/the_boiler_room" app:layout_constraintEnd_toStartOf="@id/the_boiler_room_DirectionsButton" app:layout_constraintStart_toEndOf="@id/the_boiler_room_InstagramButton" /> <Button android:id="@+id/the_boiler_room_DirectionsButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/the_boiler_room" app:layout_constraintEnd_toEndOf="@id/the_boiler_room" app:layout_constraintStart_toEndOf="@id/the_boiler_room_WebsiteButton" /> <!-- The Escape Room ImageView --> <ImageView android:id="@+id/the_escape_room" android:layout_width="0dp" android:layout_height="150dp" android:layout_marginTop="10dp" android:contentDescription="@string/the_escape_room_logo" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/the_boiler_room" app:srcCompat="@drawable/activity_the_escape_room" /> <!-- Buttons under The Escape Room ImageView --> <Button android:id="@+id/the_escape_room_FacebookButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/the_escape_room" app:layout_constraintEnd_toStartOf="@id/the_escape_room_InstagramButton" app:layout_constraintStart_toStartOf="@id/the_escape_room" app:layout_constraintHorizontal_chainStyle="spread" /> <Button android:id="@+id/the_escape_room_InstagramButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/the_escape_room" app:layout_constraintEnd_toStartOf="@id/the_escape_room_WebsiteButton" app:layout_constraintStart_toEndOf="@id/the_escape_room_FacebookButton" /> <Button android:id="@+id/the_escape_room_WebsiteButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/the_escape_room" app:layout_constraintEnd_toStartOf="@id/the_escape_room_DirectionsButton" app:layout_constraintStart_toEndOf="@id/the_escape_room_InstagramButton" /> <Button android:id="@+id/the_escape_room_DirectionsButton" android:layout_width="0dp" android:layout_height="33dp" android:background="@android:color/transparent" app:layout_constraintBottom_toBottomOf="@id/the_escape_room" app:layout_constraintEnd_toEndOf="@id/the_escape_room" app:layout_constraintStart_toEndOf="@id/the_escape_room_WebsiteButton" /> </androidx.constraintlayout.widget.ConstraintLayout> </ScrollView> 我尝试过在图像视图中设置不同的约束,我已经累了 android:layout_width="wrap_content" android:layout_height="150dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_height="150dp" 几乎我尝试过的任何不同配置,我觉得我缺少一些基本的东西。 我已经弄清楚了,我在 ScrollView 内部使用了 CardView,无论屏幕尺寸如何,图像都保持相同。我还为我的按钮使用了 LinerLayout,这样它们就会保留在图像的底部! `<?xml version="1.0" encoding="utf-8"?> <ScrollView 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:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" tools:ignore="SpeakableTextPresentCheck"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFC107" android:padding="40dp" tools:context=".ActivitiesActivity"> <androidx.cardview.widget.CardView android:id="@+id/alabama_music_hall_of_fame_card" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="8dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" app:cardCornerRadius="0dp" app:cardElevation="4dp"> <ImageView android:id="@+id/alabama_music_hall_of_fame" android:layout_width="match_parent" android:layout_height="200dp" android:src="@drawable/activity_alabama_music_hall_of_fame_card" android:scaleType="fitXY" android:contentDescription="@string/alabama_music_hall_of_fame_logo"/> <LinearLayout style="?android:attr/buttonBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="bottom" android:gravity="center_horizontal"> <Button android:id="@+id/alabama_music_hall_of_fame_FacebookButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/amhfFB" android:background="@android:color/transparent" tools:ignore="VisualLintButtonSize" /> <Button android:id="@+id/alabama_music_hall_of_fame_InstagramButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/amhfIG" android:background="@android:color/transparent" tools:ignore="VisualLintButtonSize" /> <Button android:id="@+id/alabama_music_hall_of_fame_WebsiteButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/amhfWeb" android:background="@android:color/transparent" /> <Button android:id="@+id/alabama_music_hall_of_fame_DirectionsButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/amhfDir" android:background="@android:color/transparent" tools:ignore="VisualLintButtonSize" /> </LinearLayout> </androidx.cardview.widget.CardView> <androidx.cardview.widget.CardView android:id="@+id/the_boiler_room_card" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="16dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/alabama_music_hall_of_fame_card" app:cardCornerRadius="0dp" app:cardElevation="4dp"> <ImageView android:id="@+id/the_boiler_room" android:layout_width="match_parent" android:layout_height="150dp" android:contentDescription="@string/the_boiler_room_logo" android:src="@drawable/activity_the_boiler_room" android:scaleType="fitXY"/> <LinearLayout style="?android:attr/buttonBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="bottom" android:gravity="center_horizontal"> <Button android:id="@+id/the_boiler_room_FacebookButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/tbrFB" android:background="@android:color/transparent" /> <Button android:id="@+id/the_boiler_room_InstagramButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/tbrIG" android:background="@android:color/transparent" /> <Button android:id="@+id/the_boiler_room_WebsiteButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/tbrWeb" android:background="@android:color/transparent" /> <Button android:id="@+id/the_boiler_room_DirectionsButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/tbrDir" android:background="@android:color/transparent"/> </LinearLayout> </androidx.cardview.widget.CardView> <androidx.cardview.widget.CardView android:id="@+id/the_escape_room_card" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="16dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/the_boiler_room_card" app:cardCornerRadius="0dp" app:cardElevation="4dp"> <ImageView android:id="@+id/activity_the_escape_room" android:layout_width="match_parent" android:layout_height="200dp" android:contentDescription="@string/the_escape_room_logo" android:src="@drawable/activity_the_escape_room" android:scaleType="fitXY"/> <LinearLayout style="?android:attr/buttonBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_gravity="bottom" android:gravity="center_horizontal"> <Button android:id="@+id/the_escape_room_FacebookButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/terFB" android:background="@android:color/transparent" tools:ignore="VisualLintButtonSize" /> <Button android:id="@+id/the_escape_room_InstagramButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/terIG" android:background="@android:color/transparent" /> <Button android:id="@+id/the_escape_room_WebsiteButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/terWeb" android:background="@android:color/transparent" /> <Button android:id="@+id/the_escape_room_DirectionsButton" style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:contentDescription="@string/terDir" android:background="@android:color/transparent"/> </LinearLayout> </androidx.cardview.widget.CardView> </androidx.constraintlayout.widget.ConstraintLayout> </ScrollView>`

回答 1 投票 0

毕加索以横向模式显示图像

使用Picasso库从服务器下载图像并将其放置在ImageView中,但每次它仅以横向模式显示图像,甚至最初以纵向模式显示图像。 我有一些我...

回答 3 投票 0

有什么想法为什么我的 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

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