第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Popupwindow的使用

標(biāo)簽:
Android

PopupWindow在Android.widget包下,项目中经常会使用到PopupWindow做菜单选项,  PopupWindow这个类用来实现一个弹出框,可以使用任意布局的View作为其内容,这个弹出框是悬浮在当前activity之上的。

MainActivity.java

[代码]java代码:

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

public class MainActivity   extends Activityimplements   OnClickListener { 

    

         private PopupWindow mPopWindow; 

         private View parentView; 

         private Context context; 

         ImageView   mImageViewBar; 

    

         @Override 

         protected voidonCreate(Bundle savedInstanceState)   { 

                   super.onCreate(savedInstanceState);   

                   requestWindowFeature(Window.FEATURE_NO_TITLE);   

                   setContentView(R.layout.activity_main);   

                   context   = this; 

                   initView();   

      }   

    

      private void initView() { 

        //   TODOAuto-generated method stub 

          parentView   =getLayoutInflater().inflate(R.layout.activity_main,null); 

          mImageViewBar   =(ImageView) findViewById(R.id.menu); 

          mImageViewBar.setOnClickListener(this);   

          showPopupWindow();   

     } 

    

      private void showPopupWindow() { 

           LayoutInflater   inflater = (LayoutInflater)context 

            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);   

          View   contentView =inflater.inflate(R.layout.popuplayout,null); 

          mPopWindow   = newPopupWindow(contentView); 

          mPopWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);   

          mPopWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);   

          mPopWindow   = newPopupWindow(); 

          //   设置SelectPicPopupWindow的View 

          mPopWindow.setContentView(contentView);   

          //   设置SelectPicPopupWindow弹出窗体的宽 

          mPopWindow.setWidth(LayoutParams.WRAP_CONTENT);   

          //   设置SelectPicPopupWindow弹出窗体的高 

          mPopWindow.setHeight(LayoutParams.WRAP_CONTENT);   

          //   设置SelectPicPopupWindow弹出窗体可点击 

         mPopWindow.setFocusable(true);   

         mPopWindow.setOutsideTouchable(true);   

         //   刷新状态   

         mPopWindow.update();   

         //   实例化一个ColorDrawable颜色为半透明 

         ColorDrawable   dw = new ColorDrawable(0000000000);   

         //   点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener,设置其他控件变化等操作 

         mPopWindow.setBackgroundDrawable(dw);   

         contentView.findViewById(R.id.memu1).setOnClickListener(this);   

         contentView.findViewById(R.id.memu2).setOnClickListener(this);   

         contentView.findViewById(R.id.memu3).setOnClickListener(this);   

      }   

    

       @Override 

      public void onClick(View v) { 

         int id =v.getId(); 

         switch (id) { 

           case R.id.menu: 

                 mPopWindow.showAsDropDown(mImageViewBar);   

                 break;   

           case R.id.memu1: { 

                 Toast.makeText(context,"消息",   Toast.LENGTH_SHORT).show(); 

                 mPopWindow.dismiss();   

               }   

                break;   

           case R.id.memu2: { 

                Toast.makeText(context,"收藏",   Toast.LENGTH_SHORT).show(); 

                mPopWindow.dismiss();   

              }   

               break;   

           case R.id.memu3: { 

                Toast.makeText(context,"首页",   Toast.LENGTH_SHORT).show(); 

                mPopWindow.dismiss();   

              }   

               break;   

             }   

      }   

     

      @Override 

       protected void onDestroy() { 

           //   TODOAuto-generated method stub 

            super.onDestroy();   

           mPopWindow.dismiss();   

     } 

  }

 

 

[代码]xml代码:

?

001

002

003

004

005

006

007

008

009

010

011

012

013

014

015

016

017

018

019

020

021

022

023

024

025

026

027

028

029

030

031

032

033

034

035

036

037

038

039

040

041

042

043

044

045

046

047

048

049

050

051

052

053

054

055

056

057

058

059

060

061

062

063

064

065

066

067

068

069

070

071

072

073

074

075

076

077

078

079

080

081

082

083

084

085

086

087

088

089

090

091

092

093

094

095

096

097

098

099

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

activity_main.xml 

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayoutxmlns:androidLinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_width="match_parent" 

    android:layout_height="match_parent" 

    android:background="#FFFFFF" 

    android:orientation="vertical">   

    

    <RelativeLayout 

        android:layout_width="match_parent" 

        android:layout_height="wrap_content" 

        android:background="#E4E4E4" 

        android:minHeight="55dp">   

    

        <ImageView 

            android:layout_width="20dp" 

            android:layout_height="20dp" 

            android:layout_centerVertical="true" 

            android:layout_marginLeft="8dp" 

            android:layout_marginRight="5dp" 

            android:focusable="true" 

            android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/abc_ic_ab_back_mtrl_am_alpha"/>   

    

        <ImageView 

            android:id="@+id/menu" 

            android:layout_width="20dp" 

            android:layout_height="20dp" 

            android:layout_alignParentRight="true" 

            android:layout_centerVertical="true" 

            android:layout_marginRight="9dp" 

            android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/top_arrow_message1"/>   

    </RelativeLayout>   

    

</LinearLayout> 

popuplayout.xml 

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayoutxmlns:androidLinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_width="match_parent" 

    android:layout_height="wrap_content" 

    android:gravity="center" 

    android:orientation="vertical">   

    

    <LinearLayout 

        android:layout_width="120dp" 

        android:layout_height="130dp" 

        android:layout_marginRight="2dp" 

        android:background="@drawable/danchu" 

        android:gravity="center_vertical" 

        android:orientation="vertical">   

    

        <RelativeLayout 

            android:id="@+id/memu1" 

            android:layout_width="wrap_content" 

            android:layout_height="30dp" 

            android:layout_marginTop="5dp" 

            android:gravity="center_vertical">   

    

            <ImageView 

                android:id="@+id/xiaoxi" 

                android:layout_width="20dp" 

                android:layout_height="20dp" 

                android:layout_marginLeft="10dp" 

                android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/android_arrow_application"/>   

    

            <TextView 

                android:id="@+id/pop_computer" 

                android:layout_width="wrap_content" 

                android:layout_height="wrap_content" 

                android:layout_marginLeft="10dp" 

                android:layout_toRightOf="@+id/xiaoxi" 

                android:text="消息" 

                android:textColor="#FFFFFF"/>   

        </RelativeLayout>   

    

        <View 

            android:layout_width="wrap_content" 

            android:layout_height="1dp"/>   

    

        <RelativeLayout 

            android:id="@+id/memu2" 

            android:layout_width="wrap_content" 

            android:layout_height="30dp" 

            android:layout_marginTop="5dp" 

            android:gravity="center_vertical">   

    

            <ImageView 

                android:id="@+id/shanchu" 

                android:layout_width="20dp" 

                android:layout_height="20dp" 

                android:layout_marginLeft="10dp" 

                android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/android_arrow_profitbillsm"/>   

    

            <TextView 

                android:layout_width="wrap_content" 

                android:layout_height="wrap_content" 

                android:layout_marginLeft="10dp" 

                android:layout_toRightOf="@+id/shanchu" 

                android:text="收藏" 

                android:textColor="#FFFFFF"/>   

        </RelativeLayout>   

    

        <View 

            android:layout_width="wrap_content" 

            android:layout_height="1dp"/>   

    

        <RelativeLayout 

            android:id="@+id/memu3" 

            android:layout_width="wrap_content" 

            android:layout_height="30dp" 

            android:layout_marginBottom="5dp" 

            android:layout_marginTop="5dp" 

            android:gravity="center_vertical">   

    

            <ImageView 

                android:id="@+id/dianjifanhui" 

                android:layout_width="18dp" 

                android:layout_height="20dp" 

                android:layout_marginLeft="10dp" 

                android:class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="@drawable/dir15"/>   

    

            <TextView 

                android:id="@+id/pop_manage" 

                android:layout_width="wrap_content" 

                android:layout_height="wrap_content" 

                android:layout_marginLeft="10dp" 

                android:layout_toRightOf="@+id/dianjifanhui" 

                android:text="首页" 

                android:textColor="#FFFFFF"/>   

        </RelativeLayout>   

    

        <View 

            android:layout_width="wrap_content" 

            android:layout_height="1dp"/>   

    </LinearLayout>   

    

</LinearLayout>


项目源码:

Eclipse: http://download.csdn.net/detail/dickyqie/9615658

AndroidStudio: https://github.com/DickyQie/android-basic-control

原文链接:http://www.apkbus.com/blog-894741-63323.html

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消