Android素材库ShapeableImageView未使用app:shapeAppearanceOverlay显示预览

ckocjqey  于 2023-06-27  发布在  Android
关注(0)|答案(2)|浏览(168)

使用ShapeableImageView材质组件时出现问题,请将shapeAppearanceOverlay设置为圆形图像。它不会显示在视口中。看起来我们将可见性设置为GONE。不过,它在设备上显示得很完美。
有什么办法可以解决吗?或者因为它仍然在1.2.0-alpha05中,所以正在开发中,或者是一个已知的错误?

视口截图

设备截图

素材库

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

XML代码

  1. <com.google.android.material.imageview.ShapeableImageView
  2. android:id="@+id/v_blog_card_avatar"
  3. android:layout_width="40dp"
  4. android:layout_height="40dp"
  5. android:src="@drawable/splash_background"
  6. android:scaleType="centerCrop"
  7. app:shapeAppearanceOverlay="@style/ImageCircleTheme"
  8. app:layout_constraintTop_toBottomOf="@+id/v_blog_card_divider"
  9. app:layout_constraintStart_toStartOf="parent"
  10. app:layout_constraintBottom_toBottomOf="parent"
  11. android:layout_marginBottom="16dp"
  12. android:layout_marginStart="16dp"/>

风格

  1. <style name="ImageCircleTheme">
  2. <item name="cornerFamily">rounded</item>
  3. <item name="cornerSize">50%</item>
  4. </style>
llew8vvj

llew8vvj1#

试试这个
style.xml

  1. <resources>
  2. <!-- Base application theme. -->
  3. <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
  4. <item name="colorPrimary">@color/colorPrimary</item>
  5. <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  6. <item name="colorAccent">@color/colorAccent</item>
  7. </style>
  8. <!-- ShapeableImageView theme. (note that the parent matches the Base App theme) -->
  9. <style name="ShapeAppearance.ImageView" parent="Theme.MaterialComponents.Light.DarkActionBar">
  10. <item name="cornerFamily">rounded</item>
  11. <item name="cornerSize">50%</item>
  12. </style>
  13. </resources>

my_layout.xml

  1. <com.google.android.material.imageview.ShapeableImageView
  2. android:id="@+id/sivAdvImage"
  3. android:layout_width="0dp"
  4. android:layout_height="150dp"
  5. android:src="@drawable/test_image"
  6. android:scaleType="centerCrop"
  7. app:shapeAppearance="@style/ShapeAppearance.ImageView"
  8. app:layout_constraintEnd_toEndOf="parent"
  9. app:layout_constraintStart_toStartOf="parent"
  10. app:layout_constraintTop_toTopOf="parent" />

使用:com.google.android.material:material:1.3.0-alpha03

展开查看全部
aor9mmx1

aor9mmx12#

我也有同样的问题,但我换了

  1. android:src="@drawable/image"

  1. android:background="@drawable/image"

现在一切正常

相关问题