Tod*_*odd 51 android android-popupwindow
我在线查看,无法找到PopupWindow类的工作示例.我在网上找到的代码示例要么编译但是不起作用,要么使用已被删除的方法(例如Activity.getViewInflate()).
是否有一个显示PopupWindow 的简单工作示例?
Tod*_*odd 79
我基于此Google网上论坛帖子创建了一个工作示例.
要创建一个简单的PopupWindow,您需要执行以下操作:
popup_example.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Test Pop-Up"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Java代码:
LayoutInflater inflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PopupWindow pw = new PopupWindow(
inflater.inflate(R.layout.popup_example, null, false),
100,
100,
true);
// The code below assumes that the root container has an id called 'main'
pw.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0);
Run Code Online (Sandbox Code Playgroud)