首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImageView ScaleType忽略填充

ImageView ScaleType忽略填充
EN

Stack Overflow用户
提问于 2012-06-01 21:12:06
回答 4查看 16K关注 0票数 32

我有一个带有白色背景和1dp填充的Imageview设置,这创建了一个类似边框的效果,这是想要的结果。

现在,如果我将scaleType设置为centerCrop,它会忽略顶部和底部的填充。

所以我的边框仍然在左边和右边,但不在顶部和底部。

有没有人有办法阻止这种情况发生?或者另一种在图像周围创建边框的快速方法。我将它用于我的自定义网格视图

代码语言:javascript
复制
   <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" />
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-06-03 22:50:08

我刚刚遇到了同样的问题,因为我的变通方法是添加android:layout_marginRight="5dip“

代码语言:javascript
复制
<ImageView
    android:layout_width="40dp"
    android:layout_height="30dp"
    android:background="#ffffffff"
    android:src="@drawable/liveview_logo"
    android:layout_marginRight="5dip"/>
票数 -9
EN

Stack Overflow用户

发布于 2012-09-21 20:52:37

代码语言:javascript
复制
<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将遵循您选择的填充。

票数 174
EN

Stack Overflow用户

发布于 2012-06-01 21:17:18

您可以通过设置android:background="@drawable/edit_border"来设置边框

和你的edit_border:

代码语言:javascript
复制
<?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>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10850976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档