107 lines
3.8 KiB
Java
107 lines
3.8 KiB
Java
package com.ubt.jimu.widgets.screenAdaptive;
|
|
|
|
import android.content.Context;
|
|
import android.util.AttributeSet;
|
|
import android.util.DisplayMetrics;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class XLinearLayout extends LinearLayout {
|
|
private Context a;
|
|
private float b;
|
|
private float c;
|
|
private float d;
|
|
private float e;
|
|
|
|
class AutoLayoutParams extends LinearLayout.LayoutParams {
|
|
public AutoLayoutParams(XLinearLayout xLinearLayout, Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
}
|
|
}
|
|
|
|
public XLinearLayout(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.a = context;
|
|
getScreenInfo();
|
|
}
|
|
|
|
private void getScreenInfo() {
|
|
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
|
float f = displayMetrics.density;
|
|
int i = displayMetrics.densityDpi;
|
|
this.b = displayMetrics.heightPixels;
|
|
this.c = displayMetrics.widthPixels;
|
|
float f2 = this.c;
|
|
float f3 = this.b;
|
|
if (f2 < f3) {
|
|
this.c = f3;
|
|
this.b = f2;
|
|
}
|
|
this.d = this.c / 1024.0f;
|
|
this.e = this.b / 768.0f;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
public void addView(View view, int i, ViewGroup.LayoutParams layoutParams) {
|
|
if (view instanceof TextView) {
|
|
TextView textView = (TextView) view;
|
|
textView.setTextSize(0, textView.getTextSize() * this.e);
|
|
}
|
|
float paddingBottom = view.getPaddingBottom();
|
|
float paddingTop = view.getPaddingTop();
|
|
float paddingLeft = view.getPaddingLeft();
|
|
float paddingRight = view.getPaddingRight();
|
|
if (paddingBottom != 0.0f || paddingTop != 0.0f || paddingLeft != 0.0f || paddingRight != 0.0f) {
|
|
view.setPadding((int) paddingLeft, (int) paddingTop, (int) paddingRight, (int) paddingBottom);
|
|
}
|
|
LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) layoutParams;
|
|
float f = layoutParams2.width;
|
|
float f2 = layoutParams2.height;
|
|
Log.e("xLinearLayout", "childWidth==" + f);
|
|
float f3 = (float) layoutParams2.topMargin;
|
|
float f4 = (float) layoutParams2.leftMargin;
|
|
float f5 = (float) layoutParams2.bottomMargin;
|
|
float f6 = layoutParams2.rightMargin;
|
|
if (f3 != 0.0f) {
|
|
layoutParams2.topMargin = (int) ((f3 * this.e) + 0.5d);
|
|
}
|
|
if (f5 != 0.0f) {
|
|
layoutParams2.bottomMargin = (int) ((f5 * this.e) + 0.5d);
|
|
}
|
|
if (f4 != 0.0f) {
|
|
layoutParams2.leftMargin = (int) ((f4 * this.d) + 0.5d);
|
|
}
|
|
if (f6 != 0.0f) {
|
|
layoutParams2.rightMargin = (int) ((f6 * this.d) + 0.5d);
|
|
}
|
|
int i2 = (int) ((this.e * f2) + 0.5d);
|
|
if (f2 > 0.0f) {
|
|
layoutParams2.height = i2;
|
|
}
|
|
if (f > 0.0f) {
|
|
layoutParams2.width = (int) ((i2 * (f / f2)) + 0.5d);
|
|
}
|
|
super.addView(view, i, layoutParams);
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
if (getLayoutParams() instanceof FrameLayout.LayoutParams) {
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) getLayoutParams();
|
|
int i3 = layoutParams.width;
|
|
int i4 = layoutParams.height;
|
|
}
|
|
super.onMeasure(i, i2);
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.ViewGroup
|
|
public LinearLayout.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
|
|
return new AutoLayoutParams(this, this.a, attributeSet);
|
|
}
|
|
}
|