android:gravity=“center”
android:padding=“10dp”
android:text=“相册” />
<View
android:layout_width=“match_parent”
android:layout_height=“1dp”
android:background="@color/gray" />
<TextView
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:gravity=“center”
android:padding=“10dp”
android:text=“拍照” />
<View
android:layout_width=“match_parent”
android:layout_height=“1dp”
android:background="@color/gray" />
<TextView
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:gravity=“center”
android:padding=“10dp”
android:text=“取消” />
MainActivity代码
package com.wust.mypoppuwindow;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void showPoppuwindow(View v){
initPopWindow(v);
}
private void initPopWindow(View v) {
//第一步:获取布局
View contentView = getLayoutInflater().inflate(R.layout.dialog_pupwindow, null, false);
//第二步:创建 PopupWindow
final PopupWindow popupWindow = new PopupWindow(contentView,
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT,
true);
// popupWindow.setBackgroundDrawable(new ColorDrawable(Color.RED));
//第三步:显示 popupWindow
popupWindow.showAtLocation(v,Gravity.BOTTOM,0,0);
//第四步:关闭 popupWindow
contentView.postDelayed(new Runnable() {
@Override
public void run() {
popupWindow.dismiss();
}
},2000);
}
}
<?xml version="1.0" encoding="utf-8"?>main_activity.xml布局
<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=".MainActivity">
<Button
android:onClick=“showPoppuwindow”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“显示poppuwindow”/>
效果展示:
从上图中可以看到,poppuwindow 进入和退出动画很生硬,下面我们给他加点动画
添加动画
====
编写 style
编写动画 xml
// enter
<?xml version="1.0" encoding="utf-8"?>//exit
<?xml version="1.0" encoding="utf-8"?>设置属性
package com.wust.mypoppuwindow;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
Android高级架构师
由于篇幅问题,我呢也将自己当前所在技术领域的各项知识点、工具、框架等汇总成一份技术路线图,还有一些架构进阶视频、全套学习PDF文件、面试文档、源码笔记做整理一份资料。
需要的朋友可以**私信【学习】**我分享给你,希望里面的资料可以给你们一个更好的学习参考。
或者直接点击下面链接免费获取
- 330页PDF Android学习核心笔记(内含上面8大板块)
-
Android学习的系统对应视频
-
Android进阶的系统对应学习资料
- Android BAT部分大厂面试题(有解析)
好了,以上便是今天的分享,希望为各位朋友后续的学习提供方便。觉得内容不错,也欢迎多多分享给身边的朋友哈。
…(img-gDWVDCue-1645005003381)]
[外链图片转存中…(img-0zfYrWH4-1645005003382)]
-
Android学习的系统对应视频
-
Android进阶的系统对应学习资料
[外链图片转存中…(img-CRCNHlOd-1645005003383)]
- Android BAT部分大厂面试题(有解析)
[外链图片转存中…(img-qbyb9LaK-1645005003384)]
好了,以上便是今天的分享,希望为各位朋友后续的学习提供方便。觉得内容不错,也欢迎多多分享给身边的朋友哈。