【问题标题】:Android material lib ShapeableImageView is not showing preview with app:shapeAppearanceOverlayAndroid 材质库 ShapeableImageView 未显示带有 app:shapeAppearanceOverlay 的预览
【发布时间】:2020-03-04 12:31:51
【问题描述】:

使用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>

【问题讨论】:

  • 是的,伙计,你是对的。我也面临同样的问题。

标签: android material-components-android


【解决方案1】:

试试这个,

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.3.0-alpha01 中出现的图像没有修改我的样式但不是圆形的。您的代码也不起作用。它显示方形图像。
  • 对于圆形,您可以将 CornerSize 设为 50%,并检查您的基本应用程序主题,例如 style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar"
  • Essa resposta funcionou prá mim。呼!
猜你喜欢
  • 2019-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-28
  • 1970-01-01
相关资源
最近更新 更多