Android材料库ShapeableImageView在使用app:shapeAppearanceOverlay属性时无法显示预览。

6

使用ShapeableImageView材料组件并设置shapeAppearanceOverlay使其成为圆形图像存在问题,它不会在视口中显示。似乎我们将可见性设置为GONE。但是,在设备上它完美地显示。

有没有办法解决?或者因为它仍处于1.2.0-alpha05开发阶段或已知的错误?

视口截图

输入图像描述

设备截图

输入图像描述

材料库

implementation 'com.google.android.material:material:1.2.0-alpha05'

XML 代码

<com.google.android.material.imageview.ShapeableImageView
    android:id="@+id/v_blog_card_avatar"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:src="@drawable/splash_background"
    android:scaleType="centerCrop"
    app:shapeAppearanceOverlay="@style/ImageCircleTheme"
    app:layout_constraintTop_toBottomOf="@+id/v_blog_card_divider"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:layout_marginBottom="16dp"
    android:layout_marginStart="16dp"/>

样式

<style name="ImageCircleTheme">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">50%</item>
</style>

是的,伙计,你说得对。我也遇到了同样的问题。 - AkshayT
2个回答

5

尝试这样做:

style.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

   <!-- ShapeableImageView theme. (note that the parent matches the Base App theme) -->
    <style name="ShapeAppearance.ImageView" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">50%</item>
    </style>

</resources>

my_layout.xml

<com.google.android.material.imageview.ShapeableImageView
        android:id="@+id/sivAdvImage"
        android:layout_width="0dp"
        android:layout_height="150dp"
        android:src="@drawable/test_image"
        android:scaleType="centerCrop"
        app:shapeAppearance="@style/ShapeAppearance.ImageView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

适用于:com.google.android.material:material:1.3.0-alpha03


1
1.3.0-alpha01 版本中,图像出现了,没有修改我的样式,但是没有圆角。你的代码也没有起作用,它显示为方形图像。 - Code Lover
对于圆形形状,您可以使CornerSize为50%,并检查您的基本应用程序主题, style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar" - Akshay Kondekar
这个答案对我有用。谢谢! - Vicente Domingos

1

我曾经遇到同样的问题,但我进行了替换

android:src="@drawable/image"

使用

android:background="@drawable/image"

现在它运行正常


谢谢,我会试一试的。也许等我再尝试的时候,谷歌可能已经解决了这个问题。感谢你的帮助。 - Code Lover
谢谢,我会试一试的。也许等我再尝试的时候,谷歌可能已经解决了这个问题。感谢你的帮助。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接