android.widget.PopupWindow.setWidth()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中android.widget.PopupWindow.setWidth()方法的一些代码示例,展示了PopupWindow.setWidth()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PopupWindow.setWidth()方法的具体详情如下:
包路径:android.widget.PopupWindow
类名称:PopupWindow
方法名:setWidth

PopupWindow.setWidth介绍

暂无

代码示例

代码示例来源:origin: arcadefire/nice-spinner

private void measurePopUpDimension() {
  int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
  int heightSpec = MeasureSpec.makeMeasureSpec(getPopUpHeight(), MeasureSpec.AT_MOST);
  listView.measure(widthSpec, heightSpec);
  popupWindow.setWidth(listView.getMeasuredWidth());
  popupWindow.setHeight(listView.getMeasuredHeight() - dropDownListPaddingBottom);
}

代码示例来源:origin: stackoverflow.com

_p.setWidth(getWidth());
_p.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
_p.setTouchable(true);

代码示例来源:origin: HotBitmapGG/bilibili-android-client

/**
 * 设置VideoView
 */
public void setAnchorView(View view) {
  mAnchor = view;
  if (!mFromXml) {
    removeAllViews();
    mRoot = makeControllerView();
    mWindow.setContentView(mRoot);
    mWindow.setWidth(LayoutParams.MATCH_PARENT);
    mWindow.setHeight(LayoutParams.WRAP_CONTENT);
  }
  initControllerView(mRoot);
}

代码示例来源:origin: pili-engineering/PLDroidPlayer

/**
 * Set the view that acts as the anchor for the control view.
 *
 * - This can for example be a VideoView, or your Activity's main view.
 * - AudioPlayer has no anchor view, so the view parameter will be null.
 *
 * @param view
 * The view to which to anchor the controller when it is visible.
 */
@Override
public void setAnchorView(View view) {
  mAnchor = view;
  if (mAnchor == null) {
    sDefaultTimeout = 0; // show forever
  }
  if (!mFromXml) {
    removeAllViews();
    mRoot = makeControllerView();
    mWindow.setContentView(mRoot);
    mWindow.setWidth(LayoutParams.MATCH_PARENT);
    mWindow.setHeight(LayoutParams.WRAP_CONTENT);
  }
  initControllerView(mRoot);
}

代码示例来源:origin: termux/termux-app

void popup(View view, String text) {
  int width = view.getMeasuredWidth();
  int height = view.getMeasuredHeight();
  Button button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
  button.setText(text);
  button.setTextColor(TEXT_COLOR);
  button.setPadding(0, 0, 0, 0);
  button.setMinHeight(0);
  button.setMinWidth(0);
  button.setMinimumWidth(0);
  button.setMinimumHeight(0);
  button.setWidth(width);
  button.setHeight(height);
  button.setBackgroundColor(BUTTON_PRESSED_COLOR);
  popupWindow = new PopupWindow(this);
  popupWindow.setWidth(LayoutParams.WRAP_CONTENT);
  popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
  popupWindow.setContentView(button);
  popupWindow.setOutsideTouchable(true);
  popupWindow.setFocusable(false);
  popupWindow.showAsDropDown(view, 0, -2 * height);
}

代码示例来源:origin: Bearded-Hen/Android-Bootstrap

private void createDropDown() {
  ScrollView dropdownView = createDropDownView();
  dropdownWindow = new PopupWindow();
  dropdownWindow.setFocusable(true);
  dropdownWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
  if (!isInEditMode()) {
    dropdownWindow.setBackgroundDrawable(DrawableUtils.resolveDrawable(android.R.drawable
                                          .dialog_holo_light_frame, getContext()));
  }
  dropdownWindow.setContentView(dropdownView);
  dropdownWindow.setOnDismissListener(this);
  dropdownWindow.setAnimationStyle(android.R.style.Animation_Activity);
  float longestStringWidth = measureStringWidth(getLongestString(dropdownData))
      + DimenUtils.dpToPixels((baselineItemRightPadding + baselineItemLeftPadding) * bootstrapSize);
  if (longestStringWidth < getMeasuredWidth()) {
    dropdownWindow.setWidth(DimenUtils.dpToPixels(getMeasuredWidth()));
  }
  else {
    dropdownWindow.setWidth((int) longestStringWidth + DimenUtils.dpToPixels(8));
  }
}

代码示例来源:origin: ZieIony/Carbon

return true;
});
popupWindow.setWidth(getRootView().getWidth());
popupWindow.setHeight(getRootView().getHeight());
popupWindow.showAtLocation(getRootView(), Gravity.START | Gravity.TOP, 0, 0);

代码示例来源:origin: stackoverflow.com

PopupWindow popupwindow_obj = popupDisplay();
popupwindow_obj.showAsDropDown(clickbtn, -40, 18); // where u want show on view click event popupwindow.showAsDropDown(view, x, y);

public PopupWindow popupDisplay() 
{ 

  final PopupWindow popupWindow = new PopupWindow(this);

  // inflate your layout or dynamically add view
  LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

  View view = inflater.inflate(R.layout.mylayout, null);

  Button item = (Button) view.findViewById(R.id.button1);

  popupWindow.setFocusable(true);
  popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
  popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
  popupWindow.setContentView(view);

  return popupWindow;
}

代码示例来源:origin: zyyoona7/EasyPopup

private void initContentViewAndWH() {
  if (mContentView == null) {
    if (mLayoutId != 0 && mContext != null) {
      mContentView = LayoutInflater.from(mContext).inflate(mLayoutId, null);
    } else {
      throw new IllegalArgumentException("The content view is null,the layoutId=" + mLayoutId + ",context=" + mContext);
    }
  }
  mPopupWindow.setContentView(mContentView);
  if (mWidth > 0 || mWidth == ViewGroup.LayoutParams.WRAP_CONTENT || mWidth == ViewGroup.LayoutParams.MATCH_PARENT) {
    mPopupWindow.setWidth(mWidth);
  } else {
    mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
  }
  if (mHeight > 0 || mHeight == ViewGroup.LayoutParams.WRAP_CONTENT || mHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
    mPopupWindow.setHeight(mHeight);
  } else {
    mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
  }
  //测量contentView大小
  //可能不准
  measureContentView();
  //获取contentView的精准大小
  registerOnGlobalLayoutListener();
  mPopupWindow.setInputMethodMode(mInputMethodMode);
  mPopupWindow.setSoftInputMode(mSoftInputMode);
}

代码示例来源:origin: multidots/android-app-common-tasks

WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
float width = (wm.getDefaultDisplay().getWidth() * 2) / 3;
popupWindow.setWidth((int) width);
popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);

代码示例来源:origin: multidots/android-app-common-tasks

WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
float width = (wm.getDefaultDisplay().getWidth() * 2) / 3;
popupWindow.setWidth((int) width);
popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);

代码示例来源:origin: pili-engineering/PLDroidShortVideo

/**
 * Set the view that acts as the anchor for the control view.
 *
 * - This can for example be a VideoView, or your Activity's main view.
 * - AudioPlayer has no anchor view, so the view parameter will be null.
 *
 * @param view
 * The view to which to anchor the controller when it is visible.
 */
@Override
public void setAnchorView(View view) {
  mAnchor = view;
  if (mAnchor == null) {
    sDefaultTimeout = 0; // show forever
  }
  if (!mFromXml) {
    removeAllViews();
    mRoot = makeControllerView();
    mWindow.setContentView(mRoot);
    mWindow.setWidth(FrameLayout.LayoutParams.MATCH_PARENT);
    mWindow.setHeight(FrameLayout.LayoutParams.WRAP_CONTENT);
  }
  initControllerView(mRoot);
}

代码示例来源:origin: curtis2/SuperVideoPlayer

/**
 * Set the view that acts as the anchor for the control view. This can for
 * example be a VideoView, or your Activity's main view.
 *
 * @param view The view to which to anchor the controller when it is visible.
 */
public void setAnchorView(View view) {
  mAnchor = view;
  if (!mFromXml) {
    removeAllViews();
    mRoot = makeControllerView();
    mWindow.setContentView(mRoot);
    mWindow.setWidth(LayoutParams.MATCH_PARENT);
    mWindow.setHeight(LayoutParams.WRAP_CONTENT);
  }
  initControllerView(mRoot);
  initOtherView();
}

代码示例来源:origin: stackoverflow.com

popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setContentView(popupView);

代码示例来源:origin: stackoverflow.com

LayoutInflater layoutInflater = LayoutInflater.from(context);
View layout = layoutInflater.inflate(R.layout.popup_layout, null);
PopupWindow popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(ListPopupWindow.WRAP_CONTENT);
popup.setHeight(ListPopupWindow.WRAP_CONTENT);

代码示例来源:origin: yaozs/YzsLib

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  popupWindow.setWidth(MeasureSpec.getSize(widthMeasureSpec));
  popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

代码示例来源:origin: MasayukiSuda/BubbleLayout

public static PopupWindow create(@NonNull Context context, @NonNull BubbleLayout bubbleLayout) {
  PopupWindow popupWindow = new PopupWindow(context);
  popupWindow.setContentView(bubbleLayout);
  popupWindow.setOutsideTouchable(true);
  popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
  popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
  popupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
  // change background color to transparent
  popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.popup_window_transparent));
  return popupWindow;
}

代码示例来源:origin: skydoves/PowerMenu

/**
 * sets the width of the popup menu.
 *
 * @param width width of the popup menu.
 */
public void setWidth(int width) {
  this.menuWindow.setWidth(width);
  FrameLayout.LayoutParams layoutParams =
      (FrameLayout.LayoutParams) menuListView.getLayoutParams();
  layoutParams.width = width - contentViewPadding;
  getMenuListView().setLayoutParams(layoutParams);
}

代码示例来源:origin: osfans/trime

void postShowFloatingWindow() {
 if (Function.isEmpty(Rime.getCompositionText())) {
  hideComposition();
  return;
 }
 mCompositionContainer.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
 mFloatingWindow.setWidth(mCompositionContainer.getMeasuredWidth());
 mFloatingWindow.setHeight(mCompositionContainer.getMeasuredHeight());
 post(this);
}

代码示例来源:origin: MCMrARM/revolution-irc

private void showDropDown() {
  updatePopupAnchor();
  int h = Math.min(mCommandAdapter.getItemCount() * mPopupItemHeight, mMaxPopupHeight);
  if (!mPopupWindow.isShowing()) {
    mPopupWindow.setWidth(getWidth());
    mPopupWindow.setHeight(h);
    mPopupWindow.showAsDropDown(mPopupAnchor, 0,
        getLayout().getLineTop(getLayout().getLineForOffset(getSelectionStart())));
  } else {
    mPopupWindow.update(mPopupAnchor, getWidth(), h);
  }
}

相关文章