我有一个带有白色背景和1dp填充的Imageview设置,这创建了一个类似边框的效果,这是想要的结果。
现在,如果我将scaleType设置为centerCrop,它会忽略顶部和底部的填充。
所以我的边框仍然在左边和右边,但不在顶部和底部。
有没有人有办法阻止这种情况发生?或者另一种在图像周围创建边框的快速方法。我将它用于我的自定义网格视图
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#FFFFFF"
android:contentDescription="@string/test"
android:padding="1dp"
android:src="@drawable/some_photo"
android:scaleType="centerCrop" />发布于 2012-06-03 22:50:08
我刚刚遇到了同样的问题,因为我的变通方法是添加android:layout_marginRight="5dip“
<ImageView
android:layout_width="40dp"
android:layout_height="30dp"
android:background="#ffffffff"
android:src="@drawable/liveview_logo"
android:layout_marginRight="5dip"/>发布于 2012-09-21 20:52:37
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:contentDescription="@string/test"
android:padding="1dp"
android:src="@drawable/some_photo"
android:cropToPadding="true"
android:scaleType="centerCrop" />您只需要添加android:cropToPadding
android:cropToPadding="true“
然后imageView将遵循您选择的填充。
发布于 2012-06-01 21:17:18
您可以通过设置android:background="@drawable/edit_border"来设置边框
和你的edit_border:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="2dp"
android:color="#EBDDE2" />
<padding
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="4dp" />
<gradient
android:centerColor="@color/white"
android:endColor="@color/white"
android:startColor="@color/white" />
<corners android:radius="8dp" />
</shape>https://stackoverflow.com/questions/10850976
复制相似问题