@@ -0,0 +1,2026 @@
+package lx.af.view;%0D%0A%0D%0Aimport android.content.Context;%0D%0Aimport android.content.res.TypedArray;%0D%0Aimport android.util.AttributeSet;%0D%0Aimport android.view.ViewGroup;%0D%0Aimport android.widget.ImageView;%0D%0Aimport android.widget.RelativeLayout;%0D%0A%0D%0Aimport lx.af.R;%0D%0A%0D%0A/**%0D%0A * author: lx%0D%0A * date: 16-1-7%0D%0A */%0D%0Apublic class RatioWidthRelativeLayout extends RelativeLayout %7B%0D%0A%0D%0A    private float mRatio;%0D%0A%0D%0A    public RatioWidthRelativeLayout(Context context, AttributeSet attrs, int defStyle) %7B%0D%0A        super(context, attrs, defStyle);%0D%0A        parseAttr(context, attrs);%0D%0A    %7D%0D%0A%0D%0A    public RatioWidthRelativeLayout(Context context, AttributeSet attrs) %7B%0D%0A        super(context, attrs);%0D%0A        parseAttr(context, attrs);%0D%0A    %7D%0D%0A%0D%0A    public RatioWidthRelativeLayout(Context context) %7B%0D%0A        super(context);%0D%0A    %7D%0D%0A%0D%0A    public void setRatio(float ratio) %7B%0D%0A        mRatio = ratio;%0D%0A        requestLayout();%0D%0A    %7D%0D%0A%0D%0A    public float getRatio() %7B%0D%0A        return mRatio;%0D%0A    %7D%0D%0A%0D%0A    protected void setRatioInLayout(float ratio) %7B%0D%0A        mRatio = ratio;%0D%0A    %7D%0D%0A%0D%0A    private void parseAttr(Context context, AttributeSet attrs) %7B%0D%0A        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RatioWidth);%0D%0A        mRatio = a.getFloat(R.styleable.RatioWidth_ratioByWidth, 0f);%0D%0A        a.recycle();%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    public void setLayoutParams(ViewGroup.LayoutParams params) %7B%0D%0A        if (mRatio %3E 0) %7B%0D%0A            params.height = (int) (params.width * mRatio);%0D%0A        %7D%0D%0A        super.setLayoutParams(params);%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) %7B%0D%0A        if (mRatio %3E 0) %7B%0D%0A            int width = getDefaultSize(0, widthMeasureSpec);%0D%0A            int height;%0D%0A            height = (int) (width * mRatio);%0D%0A            heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);%0D%0A            setMeasuredDimension(width, height);%0D%0A        %7D%0D%0A        super.onMeasure(widthMeasureSpec, heightMeasureSpec);%0D%0A    %7D%0D%0A%7D%0D%0A

add ratio by width RelativeLayout