am 11aa4cc3: Merge "Set width of spinner\'s dropdown to fit on device"
* commit '11aa4cc38b646f62eb22842d7510415b61c2ef84': Set width of spinner's dropdown to fit on device
This commit is contained in:
committed by
Android Git Automerger
commit
a66be97099
@@ -26,6 +26,7 @@ import android.database.DataSetObserver;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -38,13 +39,13 @@ import android.view.ViewGroup;
|
||||
*
|
||||
* <p>See the <a href="{@docRoot}resources/tutorials/views/hello-spinner.html">Spinner
|
||||
* tutorial</a>.</p>
|
||||
*
|
||||
*
|
||||
* @attr ref android.R.styleable#Spinner_prompt
|
||||
*/
|
||||
@Widget
|
||||
public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
private static final String TAG = "Spinner";
|
||||
|
||||
|
||||
// Only measure this many items to get a decent max width.
|
||||
private static final int MAX_ITEMS_MEASURED = 15;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
* Use a dialog window for selecting spinner options.
|
||||
*/
|
||||
public static final int MODE_DIALOG = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Use a dropdown anchored to the Spinner for selecting spinner options.
|
||||
*/
|
||||
@@ -732,13 +733,30 @@ public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
final Drawable background = getBackground();
|
||||
int bgOffset = 0;
|
||||
if (background != null) {
|
||||
background.getPadding(mTempRect);
|
||||
bgOffset = -mTempRect.left;
|
||||
} else {
|
||||
mTempRect.left = mTempRect.right = 0;
|
||||
}
|
||||
|
||||
final int spinnerPaddingLeft = Spinner.this.getPaddingLeft();
|
||||
if (mDropDownWidth == WRAP_CONTENT) {
|
||||
final int spinnerWidth = Spinner.this.getWidth();
|
||||
final int spinnerPaddingRight = Spinner.this.getPaddingRight();
|
||||
|
||||
int contentWidth = measureContentWidth(
|
||||
(SpinnerAdapter) mAdapter, getBackground());
|
||||
final int contentWidthLimit = mContext.getResources()
|
||||
.getDisplayMetrics().widthPixels - mTempRect.left - mTempRect.right;
|
||||
if (contentWidth > contentWidthLimit) {
|
||||
contentWidth = contentWidthLimit;
|
||||
}
|
||||
|
||||
setContentWidth(Math.max(
|
||||
measureContentWidth((SpinnerAdapter) mAdapter, getBackground()),
|
||||
spinnerWidth - spinnerPaddingLeft - spinnerPaddingRight));
|
||||
contentWidth, spinnerWidth - spinnerPaddingLeft - spinnerPaddingRight));
|
||||
} else if (mDropDownWidth == MATCH_PARENT) {
|
||||
final int spinnerWidth = Spinner.this.getWidth();
|
||||
final int spinnerPaddingRight = Spinner.this.getPaddingRight();
|
||||
@@ -746,12 +764,6 @@ public class Spinner extends AbsSpinner implements OnClickListener {
|
||||
} else {
|
||||
setContentWidth(mDropDownWidth);
|
||||
}
|
||||
final Drawable background = getBackground();
|
||||
int bgOffset = 0;
|
||||
if (background != null) {
|
||||
background.getPadding(mTempRect);
|
||||
bgOffset = -mTempRect.left;
|
||||
}
|
||||
setHorizontalOffset(bgOffset + spinnerPaddingLeft);
|
||||
setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
|
||||
super.show();
|
||||
|
||||
Reference in New Issue
Block a user