Merge "Improve RTL code for RelativeLayout" into jb-mr2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8e440a6c1a
@@ -37,7 +37,6 @@ import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewDebug;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.widget.RemoteViews.RemoteView;
|
||||
@@ -221,13 +220,13 @@ public class RelativeLayout extends ViewGroup {
|
||||
// Some apps came to rely on them. :(
|
||||
private boolean mAllowBrokenMeasureSpecs = false;
|
||||
|
||||
private int mDisplayWidth;
|
||||
// A default width used for RTL measure pass
|
||||
private static int DEFAULT_WIDTH = Integer.MAX_VALUE / 2;
|
||||
|
||||
public RelativeLayout(Context context) {
|
||||
super(context);
|
||||
mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <=
|
||||
Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||
getDisplayWidth();
|
||||
}
|
||||
|
||||
public RelativeLayout(Context context, AttributeSet attrs) {
|
||||
@@ -235,7 +234,6 @@ public class RelativeLayout extends ViewGroup {
|
||||
initFromAttributes(context, attrs);
|
||||
mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <=
|
||||
Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||
getDisplayWidth();
|
||||
}
|
||||
|
||||
public RelativeLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
@@ -243,7 +241,6 @@ public class RelativeLayout extends ViewGroup {
|
||||
initFromAttributes(context, attrs);
|
||||
mAllowBrokenMeasureSpecs = context.getApplicationInfo().targetSdkVersion <=
|
||||
Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||
getDisplayWidth();
|
||||
}
|
||||
|
||||
private void initFromAttributes(Context context, AttributeSet attrs) {
|
||||
@@ -253,11 +250,6 @@ public class RelativeLayout extends ViewGroup {
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
private void getDisplayWidth() {
|
||||
WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
mDisplayWidth = wm.getDefaultDisplay().getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldDelayChildPressedState() {
|
||||
return false;
|
||||
@@ -451,12 +443,12 @@ public class RelativeLayout extends ViewGroup {
|
||||
|
||||
// We need to know our size for doing the correct computation of children positioning in RTL
|
||||
// mode but there is no practical way to get it instead of running the code below.
|
||||
// So, instead of running the code twice, we just set the width to the "display width"
|
||||
// So, instead of running the code twice, we just set the width to a "default display width"
|
||||
// before the computation and then, as a last pass, we will update their real position with
|
||||
// an offset equals to "displayWidth - width".
|
||||
// an offset equals to "DEFAULT_WIDTH - width".
|
||||
final int layoutDirection = getLayoutDirection();
|
||||
if (isLayoutRtl() && myWidth == -1) {
|
||||
myWidth = mDisplayWidth;
|
||||
myWidth = DEFAULT_WIDTH;
|
||||
}
|
||||
|
||||
View[] views = mSortedHorizontalChildren;
|
||||
|
||||
Reference in New Issue
Block a user