gddhy

_(:з」∠)_ 加载中...
  • 主页
  • 归档
  • 工具
  • 关于
所有文章 友链

gddhy

_(:з」∠)_ 加载中...

  • 主页
  • 归档
  • 工具
  • 关于

方形ImageView

2021-12-05
字数统计:135字 阅读时长≈1分
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;

/**
* Created by libo on 2017/11/7.
*/

public class SqureImageView extends AppCompatImageView{

public SqureImageView(Context context) {
super(context);
}

public SqureImageView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//让宽度的测量尺寸代替高度尺寸
super.onMeasure(widthMeasureSpec,widthMeasureSpec);
}
}

使用

1
2
3
4
5
6
<SqureImageView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@mipmap/test4"
android:layout_marginTop="20dp"
android:scaleType="centerCrop"/>

来源:自定义view系列之——Imageview–圆形,圆角,正方形,自适应高度,设置比例 - 奔跑吧李博 | Github

赏

谢谢你请我吃糖果

微信

扫一扫,分享到微信

微信分享二维码
yilia添加一言
移动停机充值绿色通道
目录,不存在的…
留言已关闭
:gddhy
© gddhy
Hexo Theme Yilia by Litten
  • 所有文章
  • 友链

tag:

  • Android
  • 软件分享
  • game
  • Hexo
  • JavaScript
  • 旧机博物馆
  • MIUI
  • Java
  • git
  • Termux
  • mtk
  • 原神
  • Win
  • Html
  • 安卓学习笔记

    缺失模块

  • Luminous' Home
  • 影子博客
  • 四次元领域
  • 初之音
  • Mr.Pumpkin
  • ZhaoQuinn 's Blog