国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

自定義PopWindow

2019-11-09 15:55:31
字體:
來源:轉載
供稿:網友
package com.onetoo.www.onetoo.ui;import android.content.Context;import android.graphics.drawable.ColorDrawable;import android.support.v7.widget.GridLayoutManager;import android.support.v7.widget.RecyclerView;import android.view.LayoutInflater;import android.view.View;import android.widget.PopupWindow;import android.widget.RelativeLayout;import com.onetoo.www.onetoo.R;import com.onetoo.www.onetoo.abapter.home.HomeCategoryRecycleAdapter;import com.onetoo.www.onetoo.config.SpaceItemDecoration;import com.onetoo.www.onetoo.utils.DensityUtils;import java.util.ArrayList;import java.util.List;/** * Created by longShun on 2017/2/6. * desc 分類彈出框 */public class PopWindowForHomeCategory extends PopupWindow implements HomeCategoryRecycleAdapter.OnItemClickListener{ PRivate Context mContext; private View mPopWindowView; public PopWindowForHomeCategory(Context context) { super(context); this.mContext = context; initWindowView(); initPopWindow(); } private void initPopWindow() { //設置的View setContentView(mPopWindowView); //設置彈出窗體的寬 setWidth(RelativeLayout.LayoutParams.MATCH_PARENT); //設置彈出窗體的高 setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT); //設置彈出窗體可點擊 setFocusable(true); //設置彈出窗體動畫效果 setAnimationStyle(R.style.PopWindowFadeInOut);//彈出的效果 //實例化一個ColorDrawable顏色為半透明 ColorDrawable dw = new ColorDrawable(0xb0000000); //設置彈出窗體的背景 setBackgroundDrawable(dw); } private void initWindowView() { mPopWindowView = LayoutInflater.from(mContext).inflate(R.layout.home_category, null); RecyclerView mRvCategory = (RecyclerView) mPopWindowView.findViewById(R.id.rv_home_category); mRvCategory.addItemDecoration(new SpaceItemDecoration(DensityUtils.dp2px(mContext,10))); mRvCategory.setLayoutManager(new GridLayoutManager(mContext,3)); List<String> mListCategory =new ArrayList<>(); mListCategory.add("餐飲美食"); mListCategory.add("購物"); mListCategory.add("生活服務"); mListCategory.add("麗人"); mListCategory.add("休閑娛樂"); mListCategory.add("母嬰親子"); List<Integer> mListIcon = new ArrayList<>(); mListIcon.add(R.drawable.home_food); mListIcon.add(R.drawable.home_shop); mListIcon.add(R.drawable.home_service); mListIcon.add(R.drawable.home_beautiful); mListIcon.add(R.drawable.home_funny); mListIcon.add(R.drawable.home_baby); HomeCategoryRecycleAdapter adapter = new HomeCategoryRecycleAdapter(mContext, mListCategory, mListIcon); mRvCategory.setAdapter(adapter); adapter.setOnItemClickListener(this); } @Override public void onItemClick(int position) { if (onItemClickListener != null) { onItemClickListener.onItemClick(position); } } private HomeCategoryRecycleAdapter.OnItemClickListener onItemClickListener; public void setOnItemClickListener(HomeCategoryRecycleAdapter.OnItemClickListener onItemClickListener) { this.onItemClickListener = onItemClickListener; }}

動畫效果代碼: values-styles.xml

<!--首頁分類彈出框透明漸變--> <style name="PopWindowFadeInOut"> <item name="android:windowEnterAnimation">@anim/anim_fade_in</item> <item name="android:windowExitAnimation">@anim/anim_fade_out</item> </style>

res-anim目錄下動畫 anim_fade_in.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fillAfter="true" > <alpha android:fromAlpha="0" android:toAlpha="1" /></set>

anim_fade_out.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300" android:fillAfter="true" > <alpha android:fromAlpha="1" android:toAlpha="0" /></set>

使用代碼:

popWindowForHomeCategory = new PopWindowForHomeCategory(getActivity());popWindowForHomeCategory.setOnDismissListener(xxx);popWindowForHomeCategory.setOnItemClickListener(xxx);popWindowForHomeCategory.showAsDropDown(view);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 囊谦县| 荆州市| 白水县| 苍溪县| 武平县| 海淀区| 新建县| 南岸区| 会东县| 景泰县| 漳州市| 获嘉县| 宁德市| 瓮安县| 会昌县| 长春市| 安平县| 梁山县| 盐池县| 启东市| 南江县| 营山县| 尖扎县| 塔城市| 稻城县| 卫辉市| 庆安县| 鹿邑县| 衡东县| 靖宇县| 西宁市| 浦城县| 施秉县| 南皮县| 西充县| 石渠县| 通辽市| 台北市| 赫章县| 会理县| 博白县|