/** * 设置viewflow宽高比 * * @param aspectratio */ public void setAspectratio(double aspectratio) { this.mAspectRatio = aspectratio; if (this.getLayoutParams() instanceof LinearLayout.LayoutParams) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( ScreenUtil.getScreenWidthPixel(mContext), (int) (ScreenUtil.getScreenWidthPixel(mContext) / mAspectRatio)); this.setLayoutParams(params); } else if (this.getLayoutParams() instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( ScreenUtil.getScreenWidthPixel(mContext), (int) (ScreenUtil.getScreenWidthPixel(mContext) / mAspectRatio)); this.setLayoutParams(params); } }