From 8051172a285a4b5926186e40d1c7942a93c4eb15 Mon Sep 17 00:00:00 2001 From: Bjorn Bringert Date: Wed, 22 Jul 2009 19:13:39 +0100 Subject: Work around StateListDrawable padding in search suggestions Sometimes when searching, some of the suggestions had no left padding. The left-hand side icons were flush with the left edge of the screen. The problems was that setting a StateListDrawable as a background will always set the padding of a View, because of a problem in DrawableContainer. DrawableContainer.DrawableContainerState.getConstantPadding() will always return a Rect if mVariablePadding is false, which makes DrawableContainer.getPadding() return true, which causes View to change the padding. As a workaround, we use setVariablePadding(true) on the background that we create. Fixes http://b/editIssue?id=1984813 --- core/java/android/app/SuggestionsAdapter.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'core/java') diff --git a/core/java/android/app/SuggestionsAdapter.java b/core/java/android/app/SuggestionsAdapter.java index 593b7b7..4cd35a4 100644 --- a/core/java/android/app/SuggestionsAdapter.java +++ b/core/java/android/app/SuggestionsAdapter.java @@ -27,6 +27,7 @@ import android.content.res.Resources; import android.database.Cursor; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.DrawableContainer; import android.graphics.drawable.StateListDrawable; import android.net.Uri; import android.os.Bundle; @@ -359,6 +360,10 @@ class SuggestionsAdapter extends ResourceCursorAdapter { newBg.addState(new int[]{android.R.attr.state_selected}, transparent); newBg.addState(new int[]{android.R.attr.state_pressed}, transparent); newBg.addState(new int[]{}, background); + // Workaround for the fact that StateListDrawable.getPadding(Rect) always returns + // true, and thus sets the padding of any view that has it as a background. + ((DrawableContainer.DrawableContainerState) newBg.getConstantState()) + .setVariablePadding(true); mBackgroundsCache.put(backgroundColor, newBg.getConstantState()); return newBg; } -- cgit v1.1