Created
August 18, 2015 11:44
-
-
Save xxnjdlys/82ca0437befd0c31d7f1 to your computer and use it in GitHub Desktop.
hello 延安!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sadieyu.fragmenttest; | |
import android.content.Context; | |
import android.graphics.drawable.Drawable; | |
import android.util.AttributeSet; | |
import android.widget.ImageView; | |
/** | |
* Created by sadieyu | |
* Date: 15-8-18. | |
* Time: 下午7:25 | |
*/ | |
public class CustomerImgView extends ImageView { | |
public CustomerImgView(Context context) { | |
this(context,null); | |
} | |
public CustomerImgView(Context context, AttributeSet attrs) { | |
this(context, attrs,0); | |
} | |
public CustomerImgView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
@Override | |
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | |
try { | |
Drawable drawable = getDrawable(); | |
if (drawable == null) { | |
setMeasuredDimension(0, 0); | |
} else { | |
int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); | |
int measuredHeight = MeasureSpec.getSize(heightMeasureSpec); | |
if (measuredHeight == 0 && measuredWidth == 0) { | |
setMeasuredDimension(measuredWidth, measuredHeight); | |
} else if (measuredHeight == 0) { | |
int height = measuredWidth * drawable.getIntrinsicHeight() / drawable.getIntrinsicWidth(); | |
setMeasuredDimension(measuredWidth, height); | |
} else if (measuredWidth == 0){ | |
int width = measuredHeight * drawable.getIntrinsicWidth() / drawable.getIntrinsicHeight(); | |
setMeasuredDimension(width, measuredHeight); | |
} else { | |
setMeasuredDimension(measuredWidth, measuredHeight); | |
} | |
} | |
} catch (Exception e) { | |
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment