And*_*nok 7 android shapes rounded-corners drawable imageview
我对这个问题有答案,但我花了太多时间寻找它。这就是我创建这个问题的原因,这样对其他人来说会更容易。
您不能像通常的视图一样使用形状 @drawable 来圆化图像角。这就是为什么您需要对代码内的图像进行一些更改。
Ali*_*Ali 17
这是使用 Material Design ShapeableImageView执行此操作的另一种方法
为形状和形状创建一个主题cornerFamily
<style name="ImageView.Corner" parent="">
<item name="cornerSizeTopRight">8dp</item>
<item name="cornerSizeTopLeft">8dp</item>
<item name="cornerSizeBottomLeft">0dp</item>
<item name="cornerSizeBottomRight">0dp</item>
<item name="cornerFamily">rounded</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在在 XML 中添加 ShapeableImageView:
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="75dp"
android:layout_height="75dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/temp_product_image"
app:shapeAppearanceOverlay="@style/ImageView.Corner"/>
Run Code Online (Sandbox Code Playgroud)
我你想要全圆的 ShapeableImageView:
<style name="ImageView.Round" parent="">
<item name="cornerSize">50%</item>
</style>
Run Code Online (Sandbox Code Playgroud)
全圆输出:
就是这样,快乐编码:)。
| 归档时间: |
|
| 查看次数: |
4428 次 |
| 最近记录: |