亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android PopupWindow實現(xiàn)微信右上角的彈出菜單

 更新時間:2020年09月17日 08:54:10   作者:Elven_Shi  
這篇文章主要為大家詳細介紹了Android PopupWindow實現(xiàn)微信右上角的彈出菜單,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

日常開發(fā)過程中對于PopupWindown的使用也是比較多的。這里給大家展示一下PopupWindow的使用。

修改activity_main.xml布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 tools:context="${relativePackage}.${activityClass}" > 
 
 <RelativeLayout 
 android:layout_width="match_parent" 
 android:layout_height="50dip" 
 android:background="@android:color/holo_blue_dark"> 
 
 <ImageView 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:layout_centerVertical="true" 
 android:layout_marginLeft="10dip" 
 android:background="@drawable/ic_launcher" /> 
 
 <ImageView 
 android:id="@+id/rl_more" 
 android:layout_width="wrap_content" 
 android:layout_height="match_parent" 
 android:background="@drawable/ability_show_item_bg" 
 android:paddingLeft="15dp" 
 android:paddingRight="5dp" 
 android:layout_alignParentRight="true" 
 android:src="@drawable/actionbar_more_icon" /> 
 
 </RelativeLayout> 
 
</RelativeLayout> 

新建popup_window.xml布局文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:background="@android:color/white" 
 android:gravity="center_horizontal" 
 android:orientation="vertical" > 
 
 <TextView 
 android:id="@+id/settings" 
 android:layout_width="match_parent" 
 android:layout_height="45dp" 
 android:gravity="center" 
 android:padding="12dp" 
 android:text="設置" 
 android:textSize="16sp" /> 
 
 <View 
 android:layout_width="match_parent" 
 android:layout_height="1dp" 
 android:background="#BDBDBD" /> 
 
 <TextView 
 android:id="@+id/about" 
 android:layout_width="match_parent" 
 android:layout_height="45dp" 
 android:gravity="center" 
 android:padding="12dp" 
 android:text="關(guān)于" 
 android:textSize="16sp" /> 
 
 <View 
 android:layout_width="match_parent" 
 android:layout_height="1dp" 
 android:background="#BDBDBD" /> 
 
 <TextView 
 android:id="@+id/ability_logout" 
 android:layout_width="match_parent" 
 android:layout_height="45dp" 
 android:gravity="center" 
 android:padding="12dp" 
 android:text="退出" 
 android:textSize="16sp" /> 
 
</LinearLayout> 

自定義PopupWindow類PopWindow

package com.syz.mypopupwindow; 
 
import android.app.Activity; 
import android.content.Context; 
import android.graphics.drawable.ColorDrawable; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup.LayoutParams; 
import android.widget.PopupWindow; 
 
/** 
 * <p>Title:PopWindow</p> 
 * <p>Description: 自定義PopupWindow</p> 
 * @author syz 
 * @date 2016-3-14 
 */ 
public class PopWindow extends PopupWindow{ 
 private View conentView; 
 public PopWindow(final Activity context){ 
 LayoutInflater inflater = (LayoutInflater) context 
 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
 conentView = inflater.inflate(R.layout.popup_window, null); 
 int h = context.getWindowManager().getDefaultDisplay().getHeight(); 
 int w = context.getWindowManager().getDefaultDisplay().getWidth(); 
 // 設置SelectPicPopupWindow的View 
 this.setContentView(conentView); 
 // 設置SelectPicPopupWindow彈出窗體的寬 
 this.setWidth(w / 2 + 40); 
 // 設置SelectPicPopupWindow彈出窗體的高 
 this.setHeight(LayoutParams.WRAP_CONTENT); 
 // 設置SelectPicPopupWindow彈出窗體可點擊 
 this.setFocusable(true); 
 this.setOutsideTouchable(true); 
 // 刷新狀態(tài) 
 this.update(); 
 // 實例化一個ColorDrawable顏色為半透明 
 ColorDrawable dw = new ColorDrawable(0000000000); 
 // 點back鍵和其他地方使其消失,設置了這個才能觸發(fā)OnDismisslistener ,設置其他控件變化等操作 
 this.setBackgroundDrawable(dw); 
 // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog); 
 // 設置SelectPicPopupWindow彈出窗體動畫效果 
 this.setAnimationStyle(R.style.AnimationPreview); 
 
 conentView.findViewById(R.id.about).setOnClickListener(new OnClickListener() { 
 
 @Override 
 public void onClick(View arg0) { 
 //do something you need here 
 PopWindow.this.dismiss(); 
 } 
 }); 
 conentView.findViewById(R.id.ability_logout).setOnClickListener(new OnClickListener() { 
 
 @Override 
 public void onClick(View arg0) { 
 // do something before signing out 
 context.finish(); 
 PopWindow.this.dismiss(); 
 } 
 }); 
 conentView.findViewById(R.id.settings).setOnClickListener(new OnClickListener() { 
 
 @Override 
 public void onClick(View arg0) { 
 // do something you need here 
  
 PopWindow.this.dismiss(); 
 } 
 }); 
 } 
 
 /** 
 * 顯示popupWindow 
 * 
 * @param parent 
 */ 
 public void showPopupWindow(View parent) { 
 if (!this.isShowing()) { 
 // 以下拉方式顯示popupwindow 
 this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 5); 
 } else { 
 this.dismiss(); 
 } 
 } 
} 

添加自定義PopupWindow所需的style

AnimationPreview

<style name="AnimationPreview"> 
 <item name="android:windowEnterAnimation">@anim/fade_in</item> 
 <item name="android:windowExitAnimation">@anim/fade_out</item> 
 </style> 

添加style所需的動畫

fade_in.xml

<?xml version="1.0" encoding="utf-8"?> 
<!-- 左上角擴大--> 
 <scale xmlns:android="http://schemas.android.com/apk/res/android" 
 android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
 android:fromXScale="0.001" 
 android:toXScale="1.0" 
 android:fromYScale="0.001" 
 android:toYScale="1.0" 
 android:pivotX="100%" 
 android:pivotY="10%" 
 android:duration="200" /> 
    

fade_out.xml

<?xml version="1.0" encoding="utf-8"?> 
<!-- 左上角縮小 --> 
 <scale xmlns:android="http://schemas.android.com/apk/res/android" 
 android:interpolator="@android:anim/accelerate_decelerate_interpolator" 
 android:fromXScale="1.0" 
 android:toXScale="0.001" 
 android:fromYScale="1.0" 
 android:toYScale="0.001" 
 android:pivotX="100%" 
 android:pivotY="10%" 
 android:duration="200" /> 

最后在MainActivity類中使用

package com.syz.mypopupwindow; 
 
import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
 
public class MainActivity extends Activity implements OnClickListener { 
 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_main); 
 findViewById(R.id.rl_more).setOnClickListener(this); 
 } 
 
 @Override 
 public void onClick(View v) { 
 if(v.getId() == R.id.rl_more){ 
 PopWindow popWindow = new PopWindow(this); 
 popWindow.showPopupWindow(findViewById(R.id.rl_more)); 
 } 
 } 
} 

效果圖:

 

  

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

相關(guān)文章

  • android TextView實現(xiàn)跑馬燈效果

    android TextView實現(xiàn)跑馬燈效果

    這篇文章主要為大家詳細介紹了android TextView實現(xiàn)跑馬燈效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • Android編程之基于Log演示一個activity生命周期實例詳解

    Android編程之基于Log演示一個activity生命周期實例詳解

    這篇文章主要介紹了Android編程之基于Log演示一個activity生命周期,結(jié)合完整實例形式較為詳細的分析總結(jié)了Log演示activity生命周期的具體用法及Log的具體使用方法,需要的朋友可以參考下
    2015-12-12
  • 關(guān)于androidstuio導入系統(tǒng)源碼的問題

    關(guān)于androidstuio導入系統(tǒng)源碼的問題

    小編最近在做系統(tǒng)源碼導出來的小項目,在導入androidstudio過程中遇到過一些問題,本文以Schedule power on off為例給大家詳細介紹,需要的朋友參考下吧
    2021-06-06
  • 使用Kotlin+RocketMQ實現(xiàn)延時消息的示例代碼

    使用Kotlin+RocketMQ實現(xiàn)延時消息的示例代碼

    這篇文章主要介紹了使用Kotlin+RocketMQ實現(xiàn)延時消息的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-07-07
  • Android應用開發(fā)中WebView的常用方法筆記整理

    Android應用開發(fā)中WebView的常用方法筆記整理

    WebView即是在安卓本地應用中打開網(wǎng)頁視圖功能,其中對于JavaScript加載的各項操作是重點和難點,本文就為大家送上Android應用開發(fā)中WebView的常用方法筆記整理
    2016-05-05
  • Android實現(xiàn)簡單的撥號器功能

    Android實現(xiàn)簡單的撥號器功能

    這篇文章主要為大家詳細介紹了Android實現(xiàn)簡單的撥號器功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Android自定義控件實現(xiàn)水波紋效果

    Android自定義控件實現(xiàn)水波紋效果

    這篇文章主要為大家詳細介紹了Android自定義控件實現(xiàn)水波紋效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Android進階CameraX與Camera2使用比對詳解

    Android進階CameraX與Camera2使用比對詳解

    這篇文章主要為大家介紹了Android進階CameraX與Camera2使用比示例對詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01
  • Android獲取藍牙設備列表的方法

    Android獲取藍牙設備列表的方法

    這篇文章主要為大家詳細介紹了Android獲取藍牙設備列表的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • Android?利用OpenCV制作人臉檢測APP

    Android?利用OpenCV制作人臉檢測APP

    本篇文章手把手教大家使用OpenCV來實現(xiàn)一個能在安卓手機上運行的人臉檢測APP。其實不僅僅是能檢測人臉,還能檢測鼻子,嘴巴,眼睛和耳朵。需要的朋友可以參考一下
    2021-12-12

最新評論