- 浏览: 5780862 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
什么都不多说,看图先:
点击文本框,弹出最下面的PopupWindow。
很简单的啦,不解释。源码:
用法:
布局文件popwindow.xml:
styles.xml中定义的动画:
2个动画:
anim_in_bottom.xml,anim_out_bottom.xml
simple_grid_item_1_red.xml:
bg_checkbox_redball.xml:
点击文本框,弹出最下面的PopupWindow。
很简单的啦,不解释。源码:
package com.dl.view; import android.content.Context; import android.graphics.drawable.BitmapDrawable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.LinearLayout.LayoutParams; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.GridView; import android.widget.PopupWindow; import android.widget.TextView; import com.dl.app.R; public class NumbersPickerPopupWindow extends PopupWindow{ private Context context; private String[] balls=new String[]{"0","1","2","3","4","5","6","7","8","9"}; private final String split=" "; private Button btn_ok; private String selectedNumbers; private String[] selectedNumbersArray; private GridViewAdapter adapter; public NumbersPickerPopupWindow(Context context,View view,String title,String selectedNumbers){ super(view, LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT, true); this.context=context; this.selectedNumbers=selectedNumbers; selectedNumbersArray=selectedNumbers.trim().split(split); this.setBackgroundDrawable(new BitmapDrawable());//必须设置background才能消失 this.setOutsideTouchable(false); //自定义动画 this.setAnimationStyle(R.style.PopupAnimation); //使用系统动画 // mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog); this.update(); this.setTouchable(true); this.setFocusable(false); GridView gridView=(GridView)view.findViewById(R.id.gridView); adapter=new GridViewAdapter(context,balls); gridView.setAdapter(adapter); TextView tv_tips=(TextView)view.findViewById(R.id.tv_tips); tv_tips.setText(title); btn_ok=(Button)view.findViewById(R.id.btn_ok); btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub if(onOkClickListener!=null){ onOkClickListener.onOkClick(v); } if(isShowing()) dismiss(); } }); } public void setSelectedNumbers(String selectedNumbers){ this.selectedNumbers=selectedNumbers; selectedNumbersArray=selectedNumbers.trim().split(split); adapter.notifyDataSetChanged(); } class GridViewAdapter extends BaseAdapter{ private Context context; private String[] balls; public GridViewAdapter(Context context,String[] balls){ this.context=context; this.balls=balls; // num=numbers.trim().split(split); } public int getCount() { // TODO Auto-generated method stub return balls.length; } public Object getItem(int position) { // TODO Auto-generated method stub return balls[position]; } public long getItemId(int position) { // TODO Auto-generated method stub return position; } public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView==null){ convertView=LayoutInflater.from(context).inflate(R.layout.simple_grid_item_1_red, null); } CheckBox checkBox = (CheckBox)convertView.findViewById(R.id.checkBox);// checkBox.setText(balls[position]); if(selectedNumbersArray!=null&&selectedNumbersArray.length>0){ for(int i=0;i<selectedNumbersArray.length;i++){ if(selectedNumbersArray[i].equals(String.valueOf(position))){ checkBox.setChecked(true); } } } checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(onItemCheckedListener!=null){ onItemCheckedListener.onItemCheckedChanged(buttonView,isChecked); } } }); return convertView; } } //接口 private OnItemCheckedListener onItemCheckedListener; public void setOnItemCheckedListener(OnItemCheckedListener onItemCheckedListener) { this.onItemCheckedListener = onItemCheckedListener; } public interface OnItemCheckedListener{ public void onItemCheckedChanged(CompoundButton buttonView, boolean isChecked); } private OnOkClickListener onOkClickListener; public void setOnOkClickListener(OnOkClickListener onOkClickListener) { this.onOkClickListener = onOkClickListener; } public interface OnOkClickListener{ public void onOkClick(View v); } }
用法:
LayoutInflater mLayoutInflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); view = mLayoutInflater.inflate(R.layout.popwindow, null); NumbersPickerPopupWindow p=new NumbersPickerPopupWindow(context,view,"选择需要的数字","0 3 6"); p.setSelectedNumbers("1 4 6");//动态改变选中的值,之间用空格隔开 p.showAtLocation(views[0], Gravity.BOTTOM, 0, 0); //还可以定义接口 ......
布局文件popwindow.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@color/bg_blue_2" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/bg_title_bar" android:padding="5dip" > <TextView android:id="@+id/tv_tips" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="每位至少选择一个数字" android:textColor="@color/white" android:layout_centerInParent="true" /> <Button android:id="@+id/btn_ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定" android:textColor="@color/white" android:background="@drawable/bg_btn_intro" android:layout_alignParentTop="true" android:layout_alignParentRight="true" /> </RelativeLayout> <View android:layout_width="fill_parent" android:layout_height="1dip" android:background="?android:attr/listDivider" /> <GridView android:id="@+id/gridView" android:layout_width="wrap_content" android:layout_height="fill_parent" android:numColumns="5" android:horizontalSpacing="12dip" android:verticalSpacing="10dip" android:paddingTop="10dip" android:paddingBottom="10dip" android:paddingLeft="40dip" android:paddingRight="40dip" android:gravity="center" android:layout_gravity="center" /> </LinearLayout>
styles.xml中定义的动画:
<style name="PopupAnimation" parent="android:Animation" mce_bogus="1" > <item name="android:windowEnterAnimation">@anim/anim_in_bottom</item> <item name="android:windowExitAnimation">@anim/anim_out_bottom</item> </style>
2个动画:
anim_in_bottom.xml,anim_out_bottom.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="200" android:fillAfter="true" android:interpolator="@android:anim/bounce_interpolator" /> </set> <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="200" android:fillAfter="true" android:interpolator="@android:anim/bounce_interpolator" /> </set>
simple_grid_item_1_red.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" > <CheckBox android:id="@+id/checkBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="@color/white" android:gravity="center" android:button="@null" android:background="@drawable/bg_checkbox_redball" android:checked="false" /> </LinearLayout>
bg_checkbox_redball.xml:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/red_focus" /> <item android:state_checked="false" android:drawable="@drawable/red" /> </selector>
发表评论
-
NestedScrollView滚动到顶部固定子View悬停挂靠粘在顶端
2018-10-31 20:45 6816网上有一个StickyScrollView,称之为粘性Scro ... -
自定义Behavior实现AppBarLayout越界弹性效果
2017-03-31 09:33 10249一、继承AppBarLayout.Beha ... -
Android - 一种相似图片搜索算法的实现
2017-03-31 09:33 2571算法 缩小尺寸。 将图片缩小到8x8的尺寸,总共64个 ... -
使用SpringAnimation实现带下拉弹簧动画的 ScrollView
2017-03-30 11:30 2798在刚推出的 Support Library 25.3.0 里面 ... -
Android为应用添加角标(Badge)
2017-03-30 11:21 61121.需求简介 角标是什么意思呢? 看下图即可明了: 可 ... -
Android端与笔记本利用局域网进行FTP通信
2017-03-23 10:17 933先看图 打开前: 打开后: Activity类 ... -
PorterDuffColorFilter 在项目中的基本使用
2017-03-03 10:58 1303有时候标题栏会浮在内容之上,而内容会有颜色的变化,这时候就要求 ... -
ColorAnimationView 实现了滑动Viewpager 时背景色动态变化的过渡效果
2017-02-24 09:41 2175用法在注释中: import android.anima ... -
迷你轻量级全方向完美滑动处理侧滑控件SlideLayout
2017-01-16 16:53 2553纯手工超级迷你轻量级全方向完美滑动处理侧滑控件(比官方 sup ... -
Effect
2017-01-05 09:57 0https://github.com/JetradarMobi ... -
动态主题库Colorful,容易地改变App的配色方案
2016-12-27 14:49 2528Colorful是一个动态主题库,允许您很容易地改变App的配 ... -
对视图的对角线切割DiagonalView
2016-12-27 14:23 1077提供对视图的对角线切割,具有很好的用户定制 基本用法 ... -
仿淘宝京东拖拽商品详情页上下滚动黏滞效果
2016-12-26 16:53 3425比较常用的效果,有现成的,如此甚好!:) import ... -
让任意view具有滑动效果的SlideUp
2016-12-26 09:26 1666基本的类,只有一个: import android.a ... -
AdvancedWebView
2016-12-21 09:44 16https://github.com/delight-im/A ... -
可设置圆角背景边框的按钮, 通过调节色彩明度自动计算按下(pressed)状态颜色
2016-11-02 22:13 1868可设置圆角背景边框的的按钮, 通过调节色彩明度自动计算按下(p ... -
网络请求库相关
2016-10-09 09:35 62https://github.com/amitshekhari ... -
ASimpleCache一个简单的缓存框架
2015-10-26 22:53 2128ASimpleCache 是一个为android制定的 轻量级 ... -
使用ViewDragHelper实现的DragLayout开门效果
2015-10-23 10:55 3345先看一下图,有个直观的了解,向下拖动handle就“开门了”: ... -
保证图片长宽比的同时拉伸图片ImageView
2015-10-16 15:40 3683按比例放大图片,不拉伸失真 import android. ...
相关推荐
自定义popupWindow修改版
Android自定义PopupWindow,很实用
android自定义PopupWindow,实现类似微信弹框类别选项。
效果图在这里 http://www.apkbus.com/android-68461-1-1.html 这个是修改后的版本 可以点击
简单自定义的PopupWindow,有相应的点击事件,适合初学者,一看就懂。
通过自定义PopupWindow的方式,实现Spinner下拉选择列表的控件。
自定义popupWindow
本案例详细介绍了自定义PopupWindow和各种弹出显示动画,以及显示位置控制。 包括: 1> Activity中直接new PopupWindow()对象来使用; 2> 各种样式自定义PopupWindow; 3> PopupWindow的入场和出场动画样式.
自定义PopupWindow动画效果
android 封装一个通用PopupWindow,避免重复造轮子,简化代码,方便管理。
很多应用采用的底部弹出菜单实现,通过自定义PopupWindow实现
超级简单的自定义PopupWindow 子控件的四个方向 父控件的底部顶部
本Demo高仿微信朋友圈评论点赞弹出框动画效果,自定义popupwindow实现,可助你快速学习自定义popupwindow.
android 自定义popupwindow 可以多方向弹出,可以自定义位置,项目源码,直接解压
Android自定义PopupWindow日历 日期时间选择器 可自由搭配年月日时分显示,可以设置只显示年月日,不显示时分等,
主要为大家详细介绍了android自定义popupwindow仿微信右上角弹出菜单效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
android自定义下拉菜单,通过PopupWindow封装,可根据需要嵌入到工程。思路实现看文章 http://blog.csdn.net/garwen_yang/article/details/51252462