验证码

public class SpinnerImg extends ImageView {
/**
* 完成选择后启动另外一个spinner
*/
private ItemListener itemListener;
private Context mContext;
/** 下拉PopupWindow */
private UMSpinnerDropDownItems mPopupWindow;
/** 下拉布局文件 */
private LinearLayout layout;
/** 下拉布局文件创建监听器 */
private ViewCreatedListener mViewCreatedListener; public SpinnerImg(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initButton(context);
} public SpinnerImg(Context context, AttributeSet attrs) {
super(context, attrs);
initButton(context);
} public SpinnerImg(Context context, final LinearLayout layout,
ViewCreatedListener mViewCreatedListener) {
super(context);
setResIdAndViewCreatedListener(layout, mViewCreatedListener);
initButton(context);
} private void initButton(Context context) {
this.mContext = context;
// UMSpinnerButton监听事件
setOnClickListener(new UMSpinnerButtonOnClickListener());
} public PopupWindow getPopupWindow() {
return mPopupWindow;
} public void setPopupWindow(UMSpinnerDropDownItems mPopupWindow) {
this.mPopupWindow = mPopupWindow;
} public LinearLayout getResId() {
return layout;
} /**
* @Description: TODO 隐藏下拉布局
*/
public void dismiss() {
mPopupWindow.dismiss();
} /**
* @Description: TODO 设置下拉布局文件,及布局文件创建监听器
* @param @param mResId 下拉布局文件ID
* @param @param mViewCreatedListener 布局文件创建监听器
*/
public void setResIdAndViewCreatedListener(LinearLayout layout,
ViewCreatedListener mViewCreatedListener) {
this.mViewCreatedListener = mViewCreatedListener;
// 下拉布局文件id
this.layout = layout;
// 初始化PopupWindow
mPopupWindow = new UMSpinnerDropDownItems(mContext);
} /**
* UMSpinnerButton的点击事件
*/
class UMSpinnerButtonOnClickListener implements View.OnClickListener { @Override
public void onClick(View v) {
if (mPopupWindow != null) {
if (!mPopupWindow.isShowing()) {
// 设置PopupWindow弹出,退出样式
mPopupWindow.setAnimationStyle(R.style.Animation_dropdown);
// 计算popupWindow下拉x轴的位置
int lx = (SpinnerImg.this.getWidth()
- mPopupWindow.getmViewWidth() - ) / ;
// showPopupWindow
mPopupWindow.showAsDropDown(SpinnerImg.this, lx, -);
}
}
}
} /**
* @ClassName UMSpinnerDropDownItems
* @Description TODO 下拉界面
*/
public class UMSpinnerDropDownItems extends PopupWindow { private Context mContext;
/** 下拉视图的宽度 */
private int mViewWidth;
/** 下拉视图的高度 */
private int mViewHeight; public UMSpinnerDropDownItems(Context context) {
super(context);
this.mContext = context;
loadViews();
} /**
* @Description: TODO 加载布局文件
* @param
* @return void
* @throws
*/
private void loadViews() {
// 布局加载器加载布局文件
final View v = layout;
// 计算view宽高
onMeasured(v); // 必须设置
setWidth(LayoutParams.WRAP_CONTENT);
setHeight(LayoutParams.WRAP_CONTENT);
setContentView(v);
setFocusable(true); // 设置布局创建监听器,以便在实例化布局控件对象
if (mViewCreatedListener != null) {
mViewCreatedListener.onViewCreated(v);
}
} /**
* @Description: TODO 计算View长宽
* @param @param v
*/
private void onMeasured(View v) {
int w = View.MeasureSpec.makeMeasureSpec(,
View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(,
View.MeasureSpec.UNSPECIFIED);
v.measure(w, h);
mViewWidth = v.getMeasuredWidth();
mViewHeight = v.getMeasuredHeight();
} public int getmViewWidth() {
return mViewWidth;
} public void setmViewWidth(int mViewWidth) {
this.mViewWidth = mViewWidth;
} public int getmViewHeight() {
return mViewHeight;
} public void setmViewHeight(int mViewHeight) {
this.mViewHeight = mViewHeight;
} } /**
* @ClassName ViewCreatedListener
* @Description TODO 布局创建监听器,实例化布局控件对象
* @author kenny
* @date 2012-8-15
*/
public interface ViewCreatedListener {
void onViewCreated(View v);
} public void handleClick(int position) {
this.dismiss();
itemListener.endItemSelect(position);
} public void setFinishListener(ItemListener itemListener) {
this.itemListener = itemListener;
} // 接口回调数据
public static interface ItemListener {
void endItemSelect(int position);
} /**
*
* @param arryList
* spinner里面的数组
* @param whichSpinner
* 这个是哪个spinner被选择的
*
*/
public void loadListData(final LinkedList<String[]> arryList) {
this.setResIdAndViewCreatedListener(creatlayout(arryList),
new SpinnerImg.ViewCreatedListener() {
@Override
public void onViewCreated(View v) { for (int i = ; i < arryList.size(); i++) {
layout.getChildAt(i).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
SpinnerImg.this.handleClick(Integer
.valueOf(v.getTag()
.toString()));
}
});
layout.getChildAt(i).setTag(i);
}
}
});
} /**
* 创建列表布局
*
*/
public LinearLayout creatlayout(LinkedList<String[]> arryList) {
LinearLayout layout = new LinearLayout(getContext());
layout.setOrientation(LinearLayout.VERTICAL);
layout.setBackgroundColor(Color.WHITE);
for (int i = ; i < arryList.size(); i++) {
TextView tv = new TextView(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
OnlyYouHelpMe.Dp2Px(getContext(), ),
OnlyYouHelpMe.Dp2Px(getContext(), ));
tv.setLayoutParams(params);
tv.setTextColor(Color.BLACK);
tv.setGravity(Gravity.CENTER);
Drawable drawable = getResources().getDrawable(R.drawable.line_absolute);
Drawable bg = getResources().getDrawable(R.drawable.bg_text_gray);
tv.setBackgroundDrawable(bg);
drawable.setBounds(, , drawable.getMinimumWidth(),
drawable.getMinimumHeight());
tv.setCompoundDrawables(null, null, null, drawable);
tv.setPadding(, , , );
tv.setText(arryList.get(i)[]);
layout.addView(tv);
}
return layout;
} }

安卓常用 widget的更多相关文章

  1. ios 和安卓常用图标、启动图 尺寸

    ---------------------------------------------ios---------------------------------------------------- ...

  2. odoo常用widget

      widget=”statusbar” 头部状态条标签widget=”email” 电子邮件地址标签widget=”selection” 下拉选择标签widget=”mail_followers” ...

  3. 安卓常用的xml控件配件的使用包含shape,declare-styleable、selector

    今天就讲我所遇到的常用到的一些通过xml文件制作的背景效果,以后用到的话就直接使用啦!哈哈,我一向就是这么懒! 接下来,就开始介绍了 1.shape的使用,可以混合使用 xml控件配置属性 andro ...

  4. odoo视图中常用widget

    widget="statusbar" 头部状态条标签 widget="email" 电子邮件地址标签 widget="selection" ...

  5. Android的Context && 安卓常用系统服务(当前运行包名/当前网络状态和开关网络/音频服务/马达服务) (转)

    转:http://blog.csdn.net/zhandoushi1982/article/details/8501773 Context字面意思上下文,位于framework 的android.co ...

  6. Android 常用开源代码整理

    1.AndroidAnnotations一个强大的android开源注解框架, 基本上可以注入任何类型, 比一般的所谓的注入框架要快, 因为他是通过生成一个子类来实现的绑定.具体查看文档. 2.and ...

  7. 安卓TV开发(八) 移动智能终端多媒体爬虫技术 获取加载网页视频源

    转载请标明出处:http://blog.csdn.net/sk719887916/article/details/40049137,作者:skay 从上一篇学习中,学习了多媒体技术中的怎么去用josu ...

  8. Flutter 即学即用系列博客——06 超实用 Widget 集锦

    本篇文章我们来讲讲一些比较常用的 Widget. 大家验证的时候使用下面的代码替换 main.dart 代码,然后在 //TODO 语句返回下面常用 Widget 示例的代码. import 'pac ...

  9. Flutter常用插件

    Dio Dio是一个强大的Dart Http请求库,支持Restful API.FormData.拦截器.请求取消等操作.视频中将全面学习和使用Dio的操作. Flutter_swiper swipe ...

随机推荐

  1. Linux随笔(安装ftp,安装jdk,安装 tomcat,安装redis,安装MySQL)

    su: authentication failure 解决办法:sudo passwd root  更改密码即可 确认虚拟机用到的联网方式是桥接模式,不然Windows是ping不通Linux的,确保 ...

  2. 统计英文文章中各单词的频率,打印频率最高的十个单词(C语言实现)

     一.程序思路及相关代码 首先打开文件,代码如下 FILE *fp; char fname[10]; printf("请输入要分析的文件名:\n"); scanf("%s ...

  3. Openjudge-计算概论(A)-DNA排序

    描述: 给出一系列基因序列,由A,C,G,T四种字符组成.对于每一个序列,定义其逆序对如下: 序列中任意一对字符X和Y,若Y在X的右边(不一定相邻)且Y < X,则称X和Y为一个逆序对. 例如G ...

  4. Openjudge-计算概论(A)-短信计费

    描述: 用手机发短信,一条短信资费为0.1元,但限定一条短信的内容在70个字以内(包括70个字).如果你一次所发送的短信超过了70个字,则会按照每70个字一条短信的限制把它分割成多条短信发送.假设已经 ...

  5. automake,autoconf使用详解

    本文地址: http://www.laruence.com/2009/11/18/1154.html 文章转自: http://www.linuxcomputer.cn/ 作为Linux下的程序开发人 ...

  6. Quartz(任务调度)- job串行避免死锁

    参照:http://blog.csdn.net/haitaofeiyang/article/details/50737644 quartz框架中防止任务并行可以有两种方案:   1.如果是通过Meth ...

  7. 12C expdp issue

    issue 1: 使用expdp时遭遇ora-31650 D:\oracle\diag\rdbms \trace>expdp \"/ as sysdba\"  schemas ...

  8. JavaScript(7)——事件2.0

    事件 [事件类型] 不同的事件类型具有不同的信息. [UI事件] 指的是那些不一定与用户操作有关的事件.当用户与页面上的元素交互时触发. load事件:当页面完全加载后,就会 触发window 上面的 ...

  9. Calendar.getInstance()获取当天指定点上的时间[转载]

    ctoday.add(Calendar.DAY_OF_MONTH, 1); 明天时间 //获得当天0点时间public static int getTimesmorning(){Calendar ca ...

  10. Flask -- 会话

    会话session 在不同请求间存储特定用户的信息.它是在 Cookies 的基础上实现的,并且对 Cookies 进行密钥签名.这意味着用户可以查看你 Cookie 的内容,但却不能修改它,除非用户 ...