1 package com.android.car.developeroptions.datausage; 2 3 import android.annotation.Nullable; 4 import android.content.Context; 5 import android.util.AttributeSet; 6 import android.view.View; 7 import android.widget.LinearLayout; 8 9 public class MeasurableLinearLayout extends LinearLayout { 10 private View mFixedView; 11 private View mDisposableView; 12 MeasurableLinearLayout(Context context)13 public MeasurableLinearLayout(Context context) { 14 super(context, null); 15 } 16 MeasurableLinearLayout(Context context, @Nullable AttributeSet attrs)17 public MeasurableLinearLayout(Context context, @Nullable AttributeSet attrs) { 18 super(context, attrs, 0); 19 } 20 MeasurableLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr)21 public MeasurableLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 22 super(context, attrs, defStyleAttr, 0); 23 } 24 MeasurableLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)25 public MeasurableLinearLayout(Context context, AttributeSet attrs, 26 int defStyleAttr, int defStyleRes) { 27 super(context, attrs, defStyleAttr, defStyleRes); 28 } 29 30 @Override onMeasure(int widthMeasureSpec, int heightMeasureSpec)31 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 32 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 33 if (mDisposableView != null && getMeasuredWidth() - mFixedView.getMeasuredWidth() 34 < mDisposableView.getMeasuredWidth()) { 35 mDisposableView.setVisibility(GONE); 36 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 37 } else if (mDisposableView != null && mDisposableView.getVisibility() != VISIBLE) { 38 mDisposableView.setVisibility(VISIBLE); 39 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 40 } 41 } 42 setChildren(View fixedView, View disposableView)43 public void setChildren(View fixedView, View disposableView) { 44 mFixedView = fixedView; 45 mDisposableView = disposableView; 46 } 47 }