标,选“nba2k18隐藏选项”选项,将该列

Android开发(299)
1.自定义圆形控件github地址:/hdodenhof/CircleImageView
主要的类:
自定义的属性:res/values/attrs.xml
使用时的布局文件:
Demo下载:http://download.csdn.net/detail/nuptboyzhb/7284553
注意:有些开发者可能也发现了,如果我们需要一个圆形的ImageButton的话,其实,我们没有必要自己写。如果ImageButton的图标是固定不变的,我们完全可以让设计师给我设计一个圆形的图片,然后直接设置再ImageButton上就可以了。但是,请注意,我们这里的圆形ImageView是自定义控件,也即是:无论你设置的图片是什么样的,显示出来的就是圆的。比如:易信中用户头像的设置,无论用户拍什么的照片,显示出来都是一个圆的。
拓展阅读:
还有一个更加强大的RoundedImageView,还支持圆角,椭圆等等。
/vinc3m1/RoundedImageView
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:171281次
积分:6305
积分:6305
排名:第3178名
原创:451篇
转载:90篇
评论:18条
(8)(6)(12)(5)(18)(9)(66)(3)(22)(62)(89)(23)(3)(1)(1)(9)(21)(13)(4)(21)(16)(53)(12)(17)(13)(47)Android(12)
final ImageView v1 = (ImageView) findViewById(R.id.imageView1)
final ImageView v2 = (ImageView) findViewById(R.id.imageView2)
Glide.with(this).load(R.drawable.info05_1_content_img01).asBitmap().override(180, 180).diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.ic_launcher).error(R.drawable.ic_launcher).centerCrop().into(new BitmapImageViewTarget(v1) {
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), resource)
circularBitmapDrawable.setCircular(true)
v1.setImageDrawable(circularBitmapDrawable)
// 圆角矩形
Glide.with(this).load(R.drawable.info05_1_content_img01).asBitmap().override(180, 180).diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.drawable.ic_launcher).error(R.drawable.ic_launcher).centerCrop().into(new BitmapImageViewTarget(v2) {
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), resource)
circularBitmapDrawable.setCornerRadius(15)
v2.setImageDrawable(circularBitmapDrawable)
android-support-v4和glide-3.6.1下载地址:
另外附上大神写的自定义ImageView,不会OOM
package com.zhimore.mama.view.
import java.lang.ref.WeakR
import android.annotation.SuppressL
import android.content.C
import android.graphics.B
import android.graphics.Bitmap.C
import android.graphics.C
import android.graphics.C
import android.graphics.P
import android.graphics.PorterDuff.M
import android.graphics.PorterDuffX
import android.graphics.RectF;
import android.graphics.X
import android.graphics.drawable.D
import android.util.AttributeS
import android.widget.ImageV
* Created in Dec 9, :01 AM
* YOLANDA; QQ:
public class XCRoundImageViewByXfermode extends ImageView {
private Paint mP
private Xfermode mXfermode = new PorterDuffXfermode(Mode.DST_IN);
private Bitmap mMaskB
private int mRoundBorderR
private int mT
private WeakReference&Bitmap& mBufferB
public static final int TYPE_CIRCLE = 1;
* 四角圆,矩形
public static final int TYPE_ROUND = 2;
public static final int TYPE_OVAL = 3;
private static final int DEFAULT_ROUND_BORDER_RADIUS = 10;
public XCRoundImageViewByXfermode(Context context) {
this(context, null);
public XCRoundImageViewByXfermode(Context context, AttributeSet attrs) {
super(context, attrs);
mPaint = new Paint();
mPaint.setAntiAlias(true);
mType = TYPE_CIRCLE;
mRoundBorderRadius = DEFAULT_ROUND_BORDER_RADIUS;
* 测量view的大小
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (mType == TYPE_CIRCLE) {
int width = Math.min(getMeasuredWidth(), getMeasuredHeight());
setMeasuredDimension(width, width);
* 绘制view的内容
@SuppressLint("DrawAllocation")
protected void onDraw(Canvas canvas) {
Bitmap bmp = (mBufferBitmap == null ? null : mBufferBitmap.get());
if (bmp == null || bmp.isRecycled()) {
Drawable drawable = getDrawable();
if (null != drawable) {
int dwidth = drawable.getIntrinsicWidth();
int dheight = drawable.getIntrinsicHeight();
bmp = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);
float scale = 1.0f;
Canvas drawCanvas = new Canvas(bmp);
if (mType == TYPE_CIRCLE) {
scale = getWidth() * 1.0F / Math.min(dwidth, dheight);
} else if (mType == TYPE_ROUND || mType == TYPE_OVAL) {
scale = Math.max(getWidth() * 1.0f / dwidth, getHeight() * 1.0f / dheight);
drawable.setBounds(0, 0, (int) (scale * dwidth), (int) (scale * dheight));
drawable.draw(drawCanvas);
if (mMaskBitmap == null || mMaskBitmap.isRecycled()) {
mMaskBitmap = getDrawBitmap();
mPaint.reset();
mPaint.setFilterBitmap(false);
mPaint.setXfermode(mXfermode);
if (mMaskBitmap != null) {
drawCanvas.drawBitmap(mMaskBitmap, 0, 0, mPaint);
mPaint.setXfermode(null);
canvas.drawBitmap(bmp, 0, 0, null);
mBufferBitmap = new WeakReference&Bitmap&(bmp);
mPaint.setXfermode(null);
canvas.drawBitmap(bmp, 0.0f, 0.0f, mPaint);
* 绘制不同的图形Bitmap
private Bitmap getDrawBitmap() {
Bitmap bitmap = null;
bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.BLACK);
if (mType == TYPE_CIRCLE) {
canvas.drawCircle(getWidth() / 2, getWidth() / 2, getWidth() / 2, paint);
} else if (mType == TYPE_ROUND) {
canvas.drawRoundRect(new RectF(0, 0, getWidth(), getHeight()), mRoundBorderRadius, mRoundBorderRadius, paint);
} else if (mType == TYPE_OVAL) {
canvas.drawOval(new RectF(0, 0, getWidth(), getHeight()), mPaint);
} catch (Throwable e) {
* 因为使用了缓存技术,所以需要在invalidate中做些回收释放资源的处理
public void invalidate() {
mBufferBitmap = null;
if (mMaskBitmap != null) {
mMaskBitmap.recycle();
mMaskBitmap = null;
super.invalidate();
public int getRoundBorderRadius() {
return mRoundBorderR
public void setRoundBorderRadius(int mRoundBorderRadius) {
if (this.mRoundBorderRadius != mRoundBorderRadius) {
this.mRoundBorderRadius = mRoundBorderR
invalidate();
public int getType() {
return this.mT
public void setType(int mType) {
if (this.mType != mType) {
this.mType = mT
invalidate();
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:10629次
排名:千里之外
原创:20篇
转载:15篇
(1)(1)(15)(4)(2)(1)(1)(5)(3)> 博客详情
项目地址:
1. 将CircleImageView.java导入到自己的项目中。
2.布局添加: ...... xmlns:app="" ......
3. 配置文件:res/values/attrs.xml &?xml version="1.0" encoding="utf-8"?&&
&resources&&
&&& &declare-styleable name="CircleImageView"&&
&&&&&&& &attr name="border_width" format="dimension" /&&
&&&&&&& &attr name="border_color" format="color" /&&
&&& &/declare-styleable&&
&/resources&
4. 布局文件中直接使用CircleImageView: &com.youthforty.yungoubi.CircleImageView &android:id="@+id/user_head" &android:layout_width="wrap_content" &android:layout_height="wrap_content"&&&&&&& &&&&& & &android:layout_centerVertical="true" &android:layout_alignParentLeft="true" &android:layout_alignParentStart="true" &android:layout_marginLeft="8dp" &android:layout_marginStart="8dp" &android:padding="8dp" &android:src="@drawable/user_head_default" &android:contentDescription="@string/app_name" &app:border_width="2dp" &app:border_color="@color/dark" &android:onClick="btn_user_head" /&
注意:使用时不可以设置scaleType。
人打赏支持
码字总数 13090
支付宝支付
微信扫码支付
打赏金额: ¥
已支付成功
打赏金额: ¥}

我要回帖

更多关于 排列图标没有选项了 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信