Android PopWindow与GridView练习
来源:互联网 发布:中国公安大学网络教育 编辑:程序博客网 时间:2024/04/28 12:29
练习:1.首先完成如图所示效果
2.使用PopWindow与GridView完成
要求点击分享显示如图所示内容,点击取消分享退出。
并且要求进入退出动画效果为渐入渐出,时间为1秒,且要设置透明效果。
布局:
<?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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="#8ee1b4" tools:context="com.example.administrator.jreduch05.GridView_Activity"> <GridView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/gv" android:numColumns="4" > </GridView> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="取消分享" android:id="@+id/bt1" android:layout_below="@+id/gv" /></RelativeLayout>布局效果:
布局:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="match_parent"android:layout_height="match_parent"><ImageView android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/iv" android:src="@mipmap/ic_launcher" android:scaleType="centerCrop" /><TextView android:layout_width="100dp" android:layout_height="wrap_content" android:id="@+id/tv" android:gravity="center" android:text="测试" /></LinearLayout>
效果:
代码:
package com.example.administrator.jreduch05;import android.graphics.drawable.ColorDrawable;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.Gravity;import android.view.View;import android.view.WindowManager;import android.widget.Button;import android.widget.GridView;import android.widget.LinearLayout;import android.widget.PopupWindow;import android.widget.SimpleAdapter;import java.util.ArrayList;import java.util.HashMap;import java.util.List;public class PopWindow_Activity extends AppCompatActivity { private Button bt; private PopupWindow pw; private View popView; private GridView gv; private Button bt1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pop_window_); bt=(Button) findViewById(R.id.share); popView=getLayoutInflater().inflate(R.layout.activity_grid_view_,null); bt1=(Button) popView.findViewById(R.id.bt1); gv=(GridView)popView.findViewById(R.id.gv); List list =new ArrayList(); HashMap map=new HashMap(); map.put("img",R.mipmap.renrou); map.put("name","微信"); list.add(map); map=new HashMap(); map.put("img",R.mipmap.jietu1); map.put("name", "QQ"); list.add(map); map=new HashMap(); map.put("img",R.mipmap.dahai); map.put("name", "大海"); list.add(map); map=new HashMap(); map.put("img",R.mipmap.dianzan); map.put("name", "点赞"); list.add(map); SimpleAdapter sa=new SimpleAdapter(this,list,R.layout.gridlayout, new String[]{"img","name"}, new int[]{R.id.iv,R.id.tv} ); gv.setAdapter(sa); bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { pw = getPopWindow(popView); } }); bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pw.dismiss(); bt1.setVisibility(View.VISIBLE); //设置View可见 } }); } public PopupWindow getPopWindow(View view){ PopupWindow popupWindow=new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT,true ); popupWindow.setOutsideTouchable(true); popupWindow.setAnimationStyle(R.style.popStyle); //设置背景透明度 WindowManager.LayoutParams ll= getWindow().getAttributes(); ll.alpha=0.6f; getWindow().setAttributes(ll); popupWindow.setBackgroundDrawable(new ColorDrawable()); popupWindow.showAtLocation(bt, Gravity.BOTTOM, 0, 0); popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { WindowManager.LayoutParams ll= getWindow().getAttributes(); ll.alpha=1f; getWindow().setAttributes(ll); //设置View可见 } }); return popupWindow; }}完成效果:
1. 2.
0 0
- Android PopWindow与GridView练习
- PopupWindow 放gridView 点击事件 与PopWindow消失逻辑
- android PopWindow
- Android:PopWindow
- Android POPWindow
- 【Android】popWindow
- Android高级控件——ViewPager、GridView、popwindow、SlideMenu(下)
- PopWindow:基本使用与自定义PopWindow
- Android 点击PopWindow外围,PopWindow消失
- DIalog与popWindow布局
- DIalog与popWindow布局
- Dialog与PopWindow
- 与popwindow相关问题
- Android_AlertDialog与PopWindow
- Android中的popWindow
- Android中的popWindow
- android popwindow的使用
- android之popwindow操作
- leetcode No64. Minimum Path Sum
- 安装CentOS过程遇到的问题
- Java中转义字符
- ubunto16.04 安装配置
- 顺序表应用:元素位置互换之移位算法
- Android PopWindow与GridView练习
- poj 3449 Geometric Shapes 计算几何
- android利用爬虫实现模拟登录
- php会话控制
- HDU 5441--并查集
- C#托管代码和C++非托管代码互相调用
- 读写锁
- MSSQL 常见故障处理
- SpringMVC架构介绍