王立平--PopupWindow
来源:互联网 发布:淘宝全屏店招 编辑:程序博客网 时间:2024/05/16 04:15
MainActivity.java
<span style="font-size:14px;">package com.main;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.view.Gravity;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup.LayoutParams;import android.widget.Button;import android.widget.LinearLayout;import android.widget.PopupWindow;public class MainActivity extends Activity {private static final String TAG = "MainActivity";private Button button;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button = (Button) findViewById(R.id.button);button.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// 显示 popupWindowPopupWindow popupWindow = makePopupWindow(MainActivity.this);int[] xy = new int[2];button.getLocationOnScreen(xy);popupWindow.showAtLocation(button, Gravity.RIGHT | Gravity.TOP,-xy[0] / 2, xy[1] + button.getWidth());// popupWindow.showAsDropDown(button,0, 0);}});}// 创建一个包含自定义view的PopupWindowprivate PopupWindow makePopupWindow(Context cx) {PopupWindow window;window = new PopupWindow(cx);// View contentView =// LayoutInflater.from(this).inflate(R.layout.popwindow, null);// window.setContentView(contentView);Button b1 = new Button(this);b1.setText("first");b1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));Button b2 = new Button(this);b2.setText("Second");b2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));LinearLayout linearLayout = new LinearLayout(this);linearLayout.addView(b1);linearLayout.addView(b2);linearLayout.setOrientation(LinearLayout.VERTICAL);window.setContentView(linearLayout);window.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher));//window.setWidth(DisplayManager.dipToPixel(150));//window.setHeight(DisplayManager.dipToPixel(150));window.setWidth(150);window.setHeight(150);// 设置PopupWindow外部区域是否可触摸window.setFocusable(true); // 设置PopupWindow可获得焦点window.setTouchable(true); // 设置PopupWindow可触摸window.setOutsideTouchable(true); // 设置非PopupWindow区域可触摸return window;}}</span>-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:color/darker_gray" android:orientation="horizontal" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Title" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="click" /> </LinearLayout></LinearLayout></span>
0 0
- 王立平--PopupWindow
- popupwindow
- popupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- popupwindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- popupwindow
- popupwindow
- Android_Dialog_设置Dialog窗口的大小
- 解决Clover启动卡在"root device uuid is ......"的问题
- (待做)Codeforces Round.6 D. Lizards and Basements 2 dp
- 博客总纲
- opencv基础笔记(1)
- 王立平--PopupWindow
- 《C++ concurrency in action》第二章笔记
- VMWare SCSI硬盘识别
- Hduoj1789 【贪心】
- 第9周 项目5 程序填充题(3)
- leetcode - Valid Sudoku
- 8种移动APP导航设计模式对比
- 解耦HTML、CSS和JavaScript
- 招聘财务经理-食品快消品