PopupWindow
来源:互联网 发布:numbers是什么软件 编辑:程序博客网 时间:2024/06/14 01:28
代码
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button btn_pup;
private RelativeLayout relativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
relativeLayout = (RelativeLayout) findViewById(R.id.rel);
btn_pup = (Button) findViewById(R.id.btn_pup);
btn_pup.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_pup:
// 显示一个popupindoww
// 创建一个popupwindow对象
View popupview = LayoutInflater.from(this).inflate(R.layout.popupview, null);
TextView renrenTv = (TextView) popupview.findViewById(R.id.tv_renren);
renrenTv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "确定分享到人人网平台?", Toast.LENGTH_SHORT).show();
}
});
PopupWindow popupWindow = new PopupWindow(popupview, ViewGroup.LayoutParams.MATCH_PARENT, 300);
// 点击popupwindow以外的区域,popupwindow消失
popupWindow.setBackgroundDrawable(new BitmapDrawable());
// 获取焦点
popupWindow.setFocusable(true);
// 给popupwindow设置动画样式(进入、退出)
popupWindow.setAnimationStyle(R.style.mypopupstyle);
// 显示popupwindow(参数一:代表的是界面的布局容器,参数二:具体的位置由gravity去确定,参数三和参数四都是偏移量)
popupWindow.showAtLocation(relativeLayout, Gravity.BOTTOM, 0, 0);
break;
}
}
}
xml里
<?xml version="1.0" encoding="utf-8"?>
<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"
android:id="@+id/rel"
tools:context="com.example.day05popupwindow.MainActivity">
<Button
android:gravity="center"
android:id="@+id/btn_pup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="弹出一个popupwindow"
/>
</RelativeLayout>
PopupWindow要弹出的xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#00acff"
android:orientation="horizontal">
android:id="@+id/tv_renren"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="人人网"
android:textColor="#fff"
android:textSize="20sp" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="qq好友"
android:textColor="#fff"
android:textSize="20sp" />
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="朋友圈"
android:textColor="#fff"
android:textSize="20sp" />
</LinearLayout>
- popupwindow
- popupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- popupwindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- PopupWindow
- popupwindow
- popupwindow
- PopupWindow
- axios发送post请求后端接收不到的问题
- git冲突处理
- ES6 中的箭头函数
- Python学习1:Python简介
- JAVA(匿名)内部类应用(为弥补JAVA多继承的不足)
- PopupWindow
- 第21章-软件安装
- unity 学习 双击一个物体的实现
- base on fix LMAX gateway and feeder 基于FIX协议的 LMAX 流通桥和行情源
- 每天一点小知识【7】—Android7.0新特性
- opencl之code builder学习教程4
- 为 MariaDB 配置远程访问权限
- js 回调函数
- maven+ssm+oracle简单项目搭建