Fix bug #4813026 resolved direction of view doesn't change after layout direction changes
- reset resolution if setLayoutDirection() is called
- propagate resolution reset to the children if the View is a ViewGroup and direction is inherited
Change-Id: Iab1a75b17426aead7e28caba827614d7cf8e9450
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index c8f68c7..e58a605 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -4337,19 +4337,25 @@
}
/**
- * Set the layout direction for this view.
+ * Set the layout direction for this view. This will propagate a reset of layout direction
+ * resolution to the view's children and resolve layout direction for this view.
*
* @param layoutDirection One of {@link #LAYOUT_DIRECTION_LTR},
* {@link #LAYOUT_DIRECTION_RTL},
* {@link #LAYOUT_DIRECTION_INHERIT} or
* {@link #LAYOUT_DIRECTION_LOCALE}.
+ *
* @attr ref android.R.styleable#View_layoutDirection
*
* @hide
*/
@RemotableViewMethod
public void setLayoutDirection(int layoutDirection) {
- setFlags(layoutDirection, LAYOUT_DIRECTION_MASK);
+ if (getLayoutDirection() != layoutDirection) {
+ resetLayoutDirectionResolution();
+ // Setting the flag will also request a layout.
+ setFlags(layoutDirection, LAYOUT_DIRECTION_MASK);
+ }
}
/**
@@ -8881,7 +8887,8 @@
/**
* Reset the resolved layout direction by clearing the corresponding flag
*/
- private void resetLayoutDirectionResolution() {
+ void resetLayoutDirectionResolution() {
+ // Reset the current View resolution
mPrivateFlags2 &= ~LAYOUT_DIRECTION_RESOLVED;
}