Android PopupWindow使用實(shí)例
示例效果如下:
MainActivity.xml
package sn.qdj.popupwindowdemo; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.PopupWindow; /** * PopupWindow使用 * @author qingdujun * */ public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /** * popup.xml 為彈出界面布局 */ View root = getLayoutInflater().inflate(R.layout.popup, null); /** * 彈出界面 * 寬度:400 * 高度:200 */ final PopupWindow popup = new PopupWindow(root, 400,200); Button btn = (Button)findViewById(R.id.btn); Button close = (Button)findViewById(R.id.close); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub /** * 在指定位置彈出 * * 第一個(gè)參數(shù)指定PopupWindow的錨點(diǎn)view,即依附在哪個(gè)view上。 * 第二個(gè)參數(shù)指定起始點(diǎn)為parent的右下角 * 第三個(gè)參數(shù)設(shè)置以btn的下方為原點(diǎn),向左、上各偏移0像素。 */ popup.showAtLocation(findViewById(R.id.btn), Gravity.BOTTOM, 0, 0); } }); close.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub /** * 關(guān)閉PopupWindow */ popup.dismiss(); } }); } }
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" > <Button android:id="@+id/btn" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:text="彈出" /> <Button android:id="@+id/close" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_toRightOf="@id/btn" android:text="關(guān)閉" /> </RelativeLayout>
popup.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:orientation="vertical" > <Button android:id="@+id/btn1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="相冊(cè)" /> <Button android:id="@+id/btn2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="拍照" /> </LinearLayout>
- Android Popupwindow彈出窗口的簡(jiǎn)單使用方法
- Android PopupWindow使用方法小結(jié)
- Android中使用PopupWindow 仿微信點(diǎn)贊和評(píng)論彈出
- Android 使用PopupWindow實(shí)現(xiàn)彈出更多的菜單實(shí)例詳解
- Android popupwindow簡(jiǎn)單使用方法介紹
- Android組件popupwindow使用方法詳解
- Android自定義彈出窗口PopupWindow使用技巧
- Android中PopupWindow使用方法詳解
- android使用PopupWindow實(shí)現(xiàn)頁(yè)面點(diǎn)擊頂部彈出下拉菜單
- PopupWindow使用方法詳解
相關(guān)文章
Android 實(shí)現(xiàn)搶購(gòu)倒計(jì)時(shí)功能的示例
這篇文章主要介紹了Android 實(shí)現(xiàn)搶購(gòu)倒計(jì)時(shí)功能的示例,幫助大家更好的理解和學(xué)習(xí)使用Android開(kāi)發(fā),感興趣的朋友可以了解下2021-03-03Android開(kāi)發(fā)之EditText框輸入清理工具類(lèi)示例
這篇文章主要介紹了Android開(kāi)發(fā)之EditText框輸入清理工具類(lèi),涉及Android事件監(jiān)聽(tīng)及輸入框清理相關(guān)操作技巧,需要的朋友可以參考下2018-01-01Android?Camera+SurfaceView自動(dòng)聚焦防止變形拉伸
這篇文章主要為大家介紹了Android自定義相機(jī)Camera+SurfaceView實(shí)現(xiàn)自動(dòng)聚焦防止變形拉伸詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01Android自定義View實(shí)現(xiàn)遙控器按鈕
這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)遙控器按鈕,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08Android開(kāi)發(fā)控制ScrollView滑動(dòng)速度的方法
這篇文章主要介紹了Android開(kāi)發(fā)控制ScrollView滑動(dòng)速度的方法,結(jié)合實(shí)例形式分析了Android編程中ScrollView滑動(dòng)事件相關(guān)操作技巧,需要的朋友可以參考下2017-02-02Android使用Flutter實(shí)現(xiàn)錄音插件
這篇文章主要介紹了基于flutter實(shí)現(xiàn)錄音功能,介紹了如何錄音,如何把文件存放到本地,這些都是我們平常使用這個(gè)功能會(huì)遇到的問(wèn)題。在使用的過(guò)程中遇到的問(wèn)題也有列出,需要的朋友可以參考下2022-08-08Android設(shè)計(jì)模式之適配器(Adapter)模式
這篇文章主要介紹了Android設(shè)計(jì)模式之適配器(Adapter)模式,以源碼解析的方式分析適配器模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11Android APP啟動(dòng)方式、啟動(dòng)流程及啟動(dòng)優(yōu)化分析
這篇文章主要介紹了Android APP啟動(dòng)方式、啟動(dòng)流程及啟動(dòng)優(yōu)化分析的相關(guān)資料,需要的朋友可以參考下2016-09-09