Android材质库ShapeableImageView没有通过app:shapeAppearanceOverlay显示预览 [英] Android material lib ShapeableImageView is not showing preview with app:shapeAppearanceOverlay

查看:36
本文介绍了Android材质库ShapeableImageView没有通过app:shapeAppearanceOverlay显示预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ShapeableImageView 材质组件并将 shapeAppearanceOverlay 设置为圆形图像时出现问题.它不会显示在视口中.好像我们将可见性设置为 GONE .但是,它可以在设备上完美显示.

There is a problem using ShapeableImageView material component and set shapeAppearanceOverlay to make it a circle image. It doesn't show up in viewport. Seems like we set the visibility to GONE. However, it shows perfectly on the device.

有什么办法可以解决?还是因为它仍在 1.2.0-alpha05 中,所以正在开发中或已知的错误?

Is there any way to fix it? or since it is still in 1.2.0-alpha05 so under development or a known bug?

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>

推荐答案

尝试一下,

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

这篇关于Android材质库ShapeableImageView没有通过app:shapeAppearanceOverlay显示预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆