Back to project page android-utils.
The source code is released under:
Apache License
If you think the Android project android-utils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.omegar.android.utils.components; /* w ww. j av a 2 s . c om*/ import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.widget.LinearLayout; import com.omegar.android.utils.R; public class ProportionalLinearLayout extends LinearLayout { private float propotions = 1f; public ProportionalLinearLayout(Context context) { super(context); } public ProportionalLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ProportionalLinearLayout, 0, 0); try { propotions = a.getFloat( R.styleable.ProportionalLinearLayout_propotions, 1f); } finally { a.recycle(); } } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec); int height = (int) (width * propotions); super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, (int) (w * propotions), oldw, oldh); } }