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

Android簡(jiǎn)單使用PopupWindow的方法

 更新時(shí)間:2021年03月15日 09:15:51   作者:天真的趙日天  
這篇文章主要為大家詳細(xì)介紹了Android簡(jiǎn)單使用PopupWindow的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android簡(jiǎn)單使用PopupWindow的的具體代碼,供大家參考,具體內(nèi)容如下

思路

1.在res下面創(chuàng)建一個(gè)menu文件夾,并新建一個(gè)xml文件作為PoupWindow的布局文件。
2.Activity中布局填充器加載菜單布局
3.創(chuàng)建PopupWindow對(duì)象并設(shè)置內(nèi)容以及動(dòng)畫
4.設(shè)置菜單布局中控件需要做的操作

menu菜單布局:

<?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="#eaeaea"
 android:orientation="vertical">

 <Button
 android:id="@+id/bt1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="10dp"
 android:text="選項(xiàng)一" />

 <Button
 android:id="@+id/bt2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="10dp"
 android:text="選項(xiàng)二" />

 <Button
 android:id="@+id/bt3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginTop="10dp"
 android:text="選項(xiàng)三" />
</LinearLayout>

定義動(dòng)畫:

在styles資源文件里寫一個(gè)style繼承android:Animation,并設(shè)置進(jìn)出場(chǎng)效果
內(nèi)容引用res下面的anim資源文件夾里的資源文件
將動(dòng)畫綁定到popuwidow

styles資源文件

在res下面創(chuàng)建一個(gè)anim資源文件夾

anim資源文件

popupwindow綁定動(dòng)畫 popupWindow.setAnimationStyle(R.style.www);

Activity

public class MainActivity extends AppCompatActivity {
 private Button bt;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 bt = findViewById(R.id.bt);
 }

 public void click(View view) { //點(diǎn)擊事件
 View inflate = LayoutInflater.from(this).inflate(R.layout.menu, null); //布局加載器加載菜單布局
 Button bt1 = inflate.findViewById(R.id.bt1);
 Button bt2 = inflate.findViewById(R.id.bt2);
 Button bt3 = inflate.findViewById(R.id.bt3);
 /**
 * 創(chuàng)建PopupWindow對(duì)象 視圖對(duì)象, 寬, 高,缺一不可
 * 第一種:創(chuàng)建對(duì)象的時(shí)候直接加參數(shù) PopupWindow popupWindow = new PopupWindow(inflate, 200, ViewGroup.LayoutParams.WRAP_CONTENT,true);
 * 第二種 通過setContentView,setHeight,setWidth 來設(shè)置
 * 寬高可設(shè)置固定值或者ViewGroup.LayoutParams.WRAP_CONTENT
 **/
 final PopupWindow popupWindow = new PopupWindow(inflate, 200, ViewGroup.LayoutParams.WRAP_CONTENT);
 popupWindow.setOutsideTouchable(true); //點(diǎn)擊彈窗外部是否取消彈窗
 popupWindow.setAnimationStyle(R.style.www); //設(shè)置自定義好的動(dòng)畫
 //彈窗出現(xiàn)外部為陰影
 WindowManager.LayoutParams attributes = getWindow().getAttributes();
 attributes.alpha = 0.5f;
 getWindow().setAttributes(attributes);
 //彈窗取消監(jiān)聽 取消之后恢復(fù)陰影
 popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
 @Override
 public void onDismiss() {
 WindowManager.LayoutParams attributes = getWindow().getAttributes();
 attributes.alpha = 1;
 getWindow().setAttributes(attributes);
 }
 });
 //選項(xiàng)的點(diǎn)擊事件
 bt1.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View view) {
 popupWindow.dismiss();
 Toast.makeText(MainActivity.this, "選項(xiàng)一", Toast.LENGTH_SHORT).show();


 }
 });
 bt2.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View view) {
 popupWindow.dismiss();
 Toast.makeText(MainActivity.this, "選項(xiàng)二", Toast.LENGTH_SHORT).show();

 }
 });
 bt3.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View view) {
 popupWindow.dismiss();
 Toast.makeText(MainActivity.this, "選項(xiàng)三", Toast.LENGTH_SHORT).show();

 }
 });
 /**
 * 顯示popupwidow兩種方式
 * 1.howAsDropDown出現(xiàn)在下方,三個(gè)參數(shù):1綁定的控件2.x軸偏移量 3.y軸偏移量
 * 2.showAtLocation自定義位置 四個(gè)參數(shù) 1綁定的控件 2.出現(xiàn)的位置 3.x軸偏移量 4.y軸偏移量
 *
 **/
 // popupWindow.showAsDropDown(bt,0,0);
 popupWindow.showAtLocation(bt, Gravity.CENTER, 0, 0);
 }
}

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

相關(guān)文章

  • Android 倒影算法的實(shí)現(xiàn)代碼

    Android 倒影算法的實(shí)現(xiàn)代碼

    Android 倒影算法的實(shí)現(xiàn)代碼,需要的朋友可以參考一下
    2013-05-05
  • Flutter啟動(dòng)頁(閃屏頁)的具體實(shí)現(xiàn)及原理詳析

    Flutter啟動(dòng)頁(閃屏頁)的具體實(shí)現(xiàn)及原理詳析

    這篇文章主要給大家介紹了關(guān)于Flutter啟動(dòng)頁(閃屏頁)的具體實(shí)現(xiàn)及原理的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Flutter具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Android Universal ImageLoader 緩存圖片

    Android Universal ImageLoader 緩存圖片

    Universal Image Loader for Android的目的是為了實(shí)現(xiàn)異步的網(wǎng)絡(luò)圖片加載、緩存及顯示,支持多線程異步加載,通過本文給大家介紹Android Universal ImageLoader緩存圖片相關(guān)資料,涉及到imageloader緩存圖片相關(guān)知識(shí),對(duì)imageloader緩存圖片相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)
    2016-01-01
  • 深入剖析Android的Volley庫中的圖片加載功能

    深入剖析Android的Volley庫中的圖片加載功能

    這篇文章主要介紹了Android的Volley框架中的圖片加載功能,從源碼剖析了Volley加載圖片時(shí)的請(qǐng)求隊(duì)列處理等方面,需要的朋友可以參考下
    2016-04-04
  • Android使用Scroll+Fragment仿京東分類效果

    Android使用Scroll+Fragment仿京東分類效果

    這篇文章主要為大家詳細(xì)介紹了Android使用Scroll+Fragment仿京東分類效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • Android實(shí)現(xiàn)水波紋特效

    Android實(shí)現(xiàn)水波紋特效

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)水波紋特效,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Android 使用ViewPager實(shí)現(xiàn)左右循環(huán)滑動(dòng)及輪播效果

    Android 使用ViewPager實(shí)現(xiàn)左右循環(huán)滑動(dòng)及輪播效果

    ViewPager是一個(gè)常用的Android組件,不過通常我們使用ViewPager的時(shí)候不能實(shí)現(xiàn)左右無限循環(huán)滑動(dòng),在滑到邊界的時(shí)候會(huì)看到一個(gè)不能翻頁的動(dòng)畫,可能影響用戶體驗(yàn),接下來通過本文給大家介紹Android 使用ViewPager實(shí)現(xiàn)左右循環(huán)滑動(dòng)及輪播效果,一起看看吧
    2017-02-02
  • Android手勢(shì)操作識(shí)別詳解

    Android手勢(shì)操作識(shí)別詳解

    這篇文章主要為大家詳細(xì)介紹了Android手勢(shì)操作識(shí)別,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • 基于Android XML解析與保存的實(shí)現(xiàn)

    基于Android XML解析與保存的實(shí)現(xiàn)

    本篇文章小編為大家介紹,基于Android XML解析與保存的實(shí)現(xiàn)。需要的朋友參考下
    2013-04-04
  • android ListView結(jié)合xutils3仿微信實(shí)現(xiàn)下拉加載更多

    android ListView結(jié)合xutils3仿微信實(shí)現(xiàn)下拉加載更多

    本篇文章主要介紹了android ListView結(jié)合xutils3仿微信實(shí)現(xiàn)下拉加載更多,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11

最新評(píng)論

南投市| 镇巴县| 高密市| 中江县| 黎川县| 枣阳市| 肥东县| 西丰县| 峨山| 体育| 万盛区| 牡丹江市| 屏山县| 会同县| 闻喜县| 木兰县| 卓资县| 喜德县| 枝江市| 大埔县| 成安县| 伊川县| 布尔津县| 北京市| 东明县| 晋城| 静宁县| 杂多县| 邯郸县| 航空| 文成县| 泰州市| 武冈市| 平果县| 河间市| 泽库县| 浪卡子县| 高清| 东兰县| 顺昌县| 维西|