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