欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程實(shí)現(xiàn)長(zhǎng)按彈出選項(xiàng)框View進(jìn)行操作的方法

 更新時(shí)間:2017年06月19日 10:17:48   作者:Beyond0525  
這篇文章主要介紹了Android編程實(shí)現(xiàn)長(zhǎng)按彈出選項(xiàng)框View進(jìn)行操作的方法,結(jié)合實(shí)例形式分析了Android事件響應(yīng)及彈窗的功能、布局相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android編程實(shí)現(xiàn)長(zhǎng)按彈出選項(xiàng)框View進(jìn)行操作的方法。分享給大家供大家參考,具體如下:

長(zhǎng)按彈出選項(xiàng)框View進(jìn)行操作

主要代碼解釋

private void showPopWindows(View v) {
    /** pop view */
    View mPopView = LayoutInflater.from(this).inflate(R.layout.popup, null);
    final PopupWindow mPopWindow = new PopupWindow(mPopView, ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT, true);
    /** set */
    mPopWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    /** 這個(gè)很重要 ,獲取彈窗的長(zhǎng)寬度 */
    mPopView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    int popupWidth = mPopView.getMeasuredWidth();
    int popupHeight = mPopView.getMeasuredHeight();
    /** 獲取父控件的位置 */
    int[] location = new int[2];
    v.getLocationOnScreen(location);
    /** 顯示位置 */
    mPopWindow.showAtLocation(v, Gravity.NO_GRAVITY, (location[0] + v.getWidth() / 2) - popupWidth / 2, location[1]
        - popupHeight);
    mPopWindow.update();
    final String copyTxt = (String) v.getTag();
    mPopView.findViewById(R.id.tv_copy_txt).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        copyToClip(copyTxt);
        if (mPopWindow != null) {
          mPopWindow.dismiss();
        }
      }
    });
}

layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/pop_bg" >
  <TextView
    android:id="@+id/tv_copy_txt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:gravity="center"
    android:text="復(fù)制邀請(qǐng)碼"
    android:textColor="@android:color/white"
    android:textSize="12sp" />
</LinearLayout>

效果圖:

根據(jù)上面可以自行調(diào)整位置。

完整實(shí)例代碼點(diǎn)擊此處本站下載

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》及《Android資源操作技巧匯總

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論