如何在图像上添加圆角和阴影,使其看起来像附件一样?
这就是我的活动
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Content here -->
<ImageView
android:id="@+id/imageView1"
android:layout_width="107dp"
android:layout_height="166dp"
android:layout_marginStart="20dp"
android:elevation="5dp"
android:scaleType="fitCenter"
android:translationZ="12dp"
android:layout_marginTop="15dp" />
您有不同的选择。
CardView
根目录布局。LinearLayout
使用MaterialShapeDrawable
(检查这个答案)1.2.0-alpha03
中的的材料构件库,您可以更改ImageView
为新的ShapeableImageView
。就像是:
<com.google.android.material.imageview.ShapeableImageView
...
app:shapeAppearanceOverlay="@style/roundedImageView"
app:srcCompat="@drawable/ic_custom_image" />
与:
<style name="roundedImageView" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">8dp</item>
</style>
或以编程方式:
float radius = getResources().getDimension(R.dimen.corner_radius);
imageView.setShapeAppearanceModel(imageView.getShapeAppearanceModel()
.toBuilder()
.setAllCorners(CornerFamily.ROUNDED,radius)
.build());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句