我不得不创建一个类似微调器的视图,它具有以下行为:
我已经成功制作了这个视图(下面的代码),但出于某种原因,在Android 7.1上,我让弹出菜单出现在视图的顶部(甚至重叠它和它上面的视图),而不是它下面,因为它应该.这是它的样子,它应该是什么样子:
由于它是相当多的代码和资源,我把它全部放在一个Github存储库(这里),但这里是代码的主要部分(我在修复它的尝试是在注释中):
FullSizePopupSpinner.java
public class FullSizePopupSpinner extends android.support.v7.widget.AppCompatTextView {
private static final long ANIMATION_DURATION = 150;
private int[] mItemsTextsResIds, mItemsIconsResIds;
private int mSelectedItemPosition = -1;
private SpinnerPopupWindow mPopupWindow;
private boolean mInitialized = false;
private OnItemSelectedListener mOnItemSelectedListener;
private Drawable mClosedDrawable;
private Drawable mOpenedDrawable;
public interface OnItemSelectedListener {
void onItemSelected(FullSizePopupSpinner parent, int position, String item, int previousSelectedPosition);
void onNothingSelected(FullSizePopupSpinner parent);
}
public FullSizePopupSpinner(final Context context) {
super(context);
init(context);
}
public FullSizePopupSpinner(final Context …Run Code Online (Sandbox Code Playgroud) 我有这个代码.
PopupWindow popUp = new PopupWindow();
popUp.setFocusable(true);
popUp.setOutsideTouchable(true);
popUp.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
popUp.setHeight(600);
popUp.setContentView(anchorView);
popUp.showAsDropDown(anchorView);
popUp.update();
Run Code Online (Sandbox Code Playgroud)
它完美适用于Android版<Android Nougat.但是在Android Nougat中,弹出窗口显示在屏幕顶部而不是相对于锚点视图.