最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android用PopWindow做下拉框?qū)嵗a

 更新時(shí)間:2017年01月16日 14:05:10   作者:掌握當(dāng)下  
本篇文章主要介紹了android用PopWindow做下拉框?qū)嵗a,具有一定的參考價(jià)值,有興趣的可以了解一下。

最近在做下拉框,本來想用spinner,可是spinner達(dá)不到項(xiàng)目要求,跟同學(xué)同事問了一圈,都在用popwindow,網(wǎng)上看了一下,popwindow挺簡單的,可定制性挺強(qiáng)的,符合我的要求,所以,借鑒網(wǎng)上看的代碼,自己擼了一遍。寫篇博客以防忘記。

 首先,先寫個(gè)自定義布局,代碼如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="110dp"
 android:layout_height="wrap_content">
 <LinearLayout
  android:layout_width="100dp"
  android:layout_height="wrap_content"
  android:background="@drawable/bg_circle_drop_down_qr_code"
  android:orientation="vertical"
  android:layout_marginRight="@dimen/padding_10"
  android:paddingBottom="0dp"
  android:paddingLeft="@dimen/padding_5"
  android:paddingRight="@dimen/padding_5"
  android:paddingTop="@dimen/padding_5">

  <LinearLayout
   android:id="@+id/lin_scan_qr_code"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:gravity="center"
   android:orientation="horizontal"
   android:paddingBottom="@dimen/padding_5"
   android:paddingTop="@dimen/padding_5">

   <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_circle_scan_qr_code" />

   <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/padding_10"
    android:gravity="center"
    android:text="掃一掃"
    android:textColor="@color/color_white"
    android:textSize="@dimen/text_16" />
  </LinearLayout>

  <View
   android:layout_width="wrap_content"
   android:layout_height="1px"
   android:layout_marginLeft="@dimen/padding_3"
   android:layout_marginRight="@dimen/padding_3"
   android:background="@color/color_white" />

  <LinearLayout
   android:id="@+id/lin_my_qr_code"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:gravity="center"
   android:orientation="horizontal"
   android:paddingBottom="@dimen/padding_5"
   android:paddingTop="@dimen/padding_5">

   <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_circle_my_qr_code" />

   <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/padding_10"
    android:gravity="center"
    android:text="二維碼"
    android:textColor="@color/color_white"
    android:textSize="@dimen/text_16" />
  </LinearLayout>
 </LinearLayout>
</LinearLayout>

 第二步,在代碼中定義popwindow樣式,綁定點(diǎn)擊事件,代碼如下:

// // 獲取自定義布局文件pop.xml的視圖
  View customView = getActivity().getLayoutInflater().inflate(R.layout.lay_circle_pop_drop_down_qr_code,
    null, false);
  // 創(chuàng)建PopupWindow實(shí)例,200,150分別是寬度和高度

  mQrCodePopWindow = new PopupWindow(customView, CommonUtil.dipToPx(getContext(),110), ViewGroup.LayoutParams.WRAP_CONTENT,true);
  // 設(shè)置動(dòng)畫效果 [R.style.AnimationFade 是自己事先定義好的]
//  popupwindow.setAnimationStyle(R.style.AnimationFade);
//  popupwindow.setTouchable(true);
//  popupwindow.setOutsideTouchable(true);
  mQrCodePopWindow.setBackgroundDrawable(new BitmapDrawable());
  customView.findViewById(R.id.lin_scan_qr_code).setOnClickListener(v -> {
   ToastUtil.show(getContext(),"掃一掃");
   dismissQrCodePopWindow();
  });
  customView.findViewById(R.id.lin_my_qr_code).setOnClickListener(v -> ToastUtil.show(getContext(),"二維碼"));

 注意,代碼中的true為setFoucusable,如要點(diǎn)擊空白處隱藏popwindow的話,setFocusable(true)和setBackground()兩者必不可少(親測(cè))。

最后,為空間添加點(diǎn)擊事件,控制下拉框的顯示隱藏,代碼如下:

@OnClick(R.id.lin_top_right)
 public void onClick(View v) {
  if (mQrCodePopWindow != null&& mQrCodePopWindow.isShowing()) {
   mQrCodePopWindow.dismiss();
  } else {
   initQrCodePopWindow();
   mQrCodePopWindow.showAsDropDown(v);
  }
 }

(由于暫時(shí)沒有發(fā)現(xiàn)好的動(dòng)畫效果,所以沒有添加動(dòng)畫,如果大家有發(fā)現(xiàn)好的動(dòng)畫,還請(qǐng)告知一二,在此謝過)

效果圖:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android設(shè)置項(xiàng)目為系統(tǒng)APP方法

    Android設(shè)置項(xiàng)目為系統(tǒng)APP方法

    大家好,本篇文章講的是Android設(shè)置項(xiàng)目為系統(tǒng)APP介紹,感興趣的同學(xué)趕快來看一看吧,希望本篇文章對(duì)你起到幫助
    2021-11-11
  • Android實(shí)現(xiàn)讀取NFC卡的編號(hào)

    Android實(shí)現(xiàn)讀取NFC卡的編號(hào)

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)讀取NFC卡的編號(hào),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Kotlin學(xué)習(xí)筆記之const val與val

    Kotlin學(xué)習(xí)筆記之const val與val

    這篇文章主要給大家介紹了關(guān)于Kotlin學(xué)習(xí)筆記之const val與val的相關(guān)資料,并給大家介紹了const val和val區(qū)別以及Kotlin中var和val的區(qū)別,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • Android開發(fā)菜單布局之表格布局示例

    Android開發(fā)菜單布局之表格布局示例

    這篇文章主要介紹了Android開發(fā)菜單布局之表格布局,結(jié)合具體實(shí)例形式分析了Android菜單布局中表格布局的相關(guān)行列排版與設(shè)置操作技巧,需要的朋友可以參考下
    2019-04-04
  • 詳解Android 視頻滾動(dòng)列表(偷懶型)

    詳解Android 視頻滾動(dòng)列表(偷懶型)

    小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧本篇文章主要介紹了Android 視頻滾動(dòng)列表(偷懶型),
    2017-11-11
  • Android 7.0以上版本實(shí)現(xiàn)應(yīng)用內(nèi)語言切換的方法

    Android 7.0以上版本實(shí)現(xiàn)應(yīng)用內(nèi)語言切換的方法

    本篇文章主要介紹了Android 7.0以上版本實(shí)現(xiàn)應(yīng)用內(nèi)語言切換的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-02-02
  • Android 暫停和恢復(fù)Activity

    Android 暫停和恢復(fù)Activity

    在正常的應(yīng)用程序使用,前臺(tái)activity有時(shí)會(huì)被其他可視化組件遮擋,從而 造成activity的暫停。例如,當(dāng)一個(gè)半透明的activity打開時(shí)(如在一個(gè)風(fēng)格對(duì)話框),以前的activity就暫停了。只要 activity仍然是部分可見,但目前沒有獲得焦點(diǎn),它就依然處于暫停狀態(tài)
    2016-03-03
  • 詳解Android Checkbox的使用方法

    詳解Android Checkbox的使用方法

    這篇文章主要為大家詳細(xì)介紹了Android Checkbox的使用方法,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Kotlin Flow操作符及基本使用詳解

    Kotlin Flow操作符及基本使用詳解

    這篇文章主要為大家介紹了Kotlin Flow操作符及基本使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • Flutter 首頁必用組件NestedScrollView的示例詳解

    Flutter 首頁必用組件NestedScrollView的示例詳解

    今天介紹的組件是NestedScrollView,大部分的App首頁都會(huì)用到這個(gè)組件。對(duì)Flutter 首頁必用組件NestedScrollView的相關(guān)知識(shí)感興趣的一起看看吧
    2020-05-05

最新評(píng)論

高阳县| 许昌市| 绩溪县| 舒城县| 兴化市| 两当县| 诸城市| 车险| 瑞昌市| 托克逊县| 彰化县| 若羌县| 平舆县| 青海省| 青田县| 闸北区| 尤溪县| 灯塔市| 福海县| 贵阳市| 临江市| 新巴尔虎左旗| 永丰县| 郑州市| 梁河县| 嵩明县| 鄱阳县| 香港 | 葫芦岛市| 锡林浩特市| 孟津县| 宣威市| 庄浪县| 明水县| 宜章县| 全南县| 兰溪市| 什邡市| 龙门县| 靖西县| 哈尔滨市|