<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}" >    <TextView        android:id="@+id/tv_hello"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world" /></RelativeLayout>
package com.hyc.popupwindowdemo;import android.app.Activity;import android.graphics.drawable.ColorDrawable;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup.LayoutParams;import android.widget.PopupWindow;import android.widget.TextView;public class MainActivity extends Activity implements OnClickListener {private TextView tvHello = null;private PopupWindow mPopupWindow = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tvHello = (TextView) findViewById(R.id.tv_hello);tvHello.setOnClickListener(this);}@Overridepublic void onClick(View v) {TextView tv = new TextView(this);tv.setWidth(LayoutParams.WRAP_CONTENT);tv.setHeight(LayoutParams.WRAP_CONTENT);tv.setText("ok");
//注意:以下代码的顺序不可颠倒mPopupWindow = new PopupWindow(tv, 100, 100);mPopupWindow.setFocusable(true);mPopupWindow.setOutsideTouchable(true);mPopupWindow.update();mPopupWindow.setBackgroundDrawable(new ColorDrawable(0));mPopupWindow.showAsDropDown(tvHello);}}


更多相关文章

  1. 非UI线程可不可以更新UI(一)
  2. Android项目中如果json字符串中key-value顺序很重要,不要使用Andr
  3. Android中设置控件可见与不可见
  4. Android中设置控件可见与不可见详解
  5. android根据姓名首字母字符顺序读取通信录
  6. 【Android】AS环境下,在布局中使用android:gravity="left/right"
  7. 设置EditText可点击但是不可编辑
  8. android动态给view设置可见、不可见属性
  9. android 的relativelayout 报错 No resource found that matches

随机推荐

  1. php快递查询接口,一次接入顺丰、京东、申
  2. 给定一个数组$arr = [23,3,45,6,78,8,34]
  3. Spring认证_什么是Spring GraphQL?
  4. 返回数组中所有的值并给其建立从0开始递
  5. 递增的数字索引数组
  6. 完成一个用户注册页面,对表单字段进行验证
  7. 类与对象----那些事儿
  8. 【PHP】通过PHPoffice实现简单的导入
  9. 类的属性、封装、构造函数
  10. 面向对象编程(oop)初体验