If you think the Android project Implementing-ActionBarSherlock-Fragment-Tabs-in-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.actionbarsherlock.internal.widget;
/*fromwww.java2s.com*/import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
publicclass TabsLinearLayout extends IcsLinearLayout {
privatestaticfinalint[] R_styleable_LinearLayout = newint[] {
/* 0 */ android.R.attr.measureWithLargestChild,
};
privatestaticfinalint LinearLayout_measureWithLargestChild = 0;
privateboolean mUseLargestChild;
public TabsLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, /*com.android.internal.R.styleable.*/R_styleable_LinearLayout);
mUseLargestChild = a.getBoolean(/*com.android.internal.R.styleable.*/LinearLayout_measureWithLargestChild, false);
a.recycle();
}
/**
* When true, all children with a weight will be considered having
* the minimum size of the largest child. If false, all children are
* measured normally.
*
* @return True to measure children with a weight using the minimum
* size of the largest child, false otherwise.
*
* @attr ref android.R.styleable#LinearLayout_measureWithLargestChild
*/publicboolean isMeasureWithLargestChildEnabled() {
return mUseLargestChild;
}
/**
* When set to true, all children with a weight will be considered having
* the minimum size of the largest child. If false, all children are
* measured normally.
*
* Disabled by default.
*
* @param enabled True to measure children with a weight using the
* minimum size of the largest child, false otherwise.
*
* @attr ref android.R.styleable#LinearLayout_measureWithLargestChild
*/publicvoid setMeasureWithLargestChildEnabled(boolean enabled) {
mUseLargestChild = enabled;
}
@Override
protectedvoid onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
finalint childCount = getChildCount();
if (childCount <= 2) return;
finalint mode = MeasureSpec.getMode(widthMeasureSpec);
if (mUseLargestChild && mode == MeasureSpec.UNSPECIFIED) {
finalint orientation = getOrientation();
if (orientation == HORIZONTAL) {
useLargestChildHorizontal();
}
}
}
privatevoid useLargestChildHorizontal() {
finalint childCount = getChildCount();
// Find largest child width
int largestChildWidth = 0;
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
largestChildWidth = Math.max(child.getMeasuredWidth(), largestChildWidth);
}
int totalWidth = 0;
// Re-measure childs
for (int i = 0; i < childCount; i++) {
final View child = getChildAt(i);
if (child == null || child.getVisibility() == View.GONE) {
continue;
}
final LinearLayout.LayoutParams lp =
(LinearLayout.LayoutParams) child.getLayoutParams();
float childExtra = lp.weight;
if (childExtra > 0) {
child.measure(
MeasureSpec.makeMeasureSpec(largestChildWidth,
MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(child.getMeasuredHeight(),
MeasureSpec.EXACTLY));
totalWidth += largestChildWidth;
} else {
totalWidth += child.getMeasuredWidth();
}
totalWidth += lp.leftMargin + lp.rightMargin;
}
totalWidth += getPaddingLeft() + getPaddingRight();
setMeasuredDimension(totalWidth, getMeasuredHeight());
}
}