验证码

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. 后台验证url是不是有效的链接

    /** * 判断链接是否有效 * 输入链接 * 返回true或者false */ public static boolean isValid(String strLink){ URL url=null ...

  2. java 导出excel(读数据库案例)

    import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.S ...

  3. zookeeper(1)

    参考文档:zookeeper中文网 一.介绍安装 zookeeper 是一个高效的分布式协调服务,它暴露了一些公用服务,比如命名/配置/同步控制/群组服务等.我们可以使用ZK来实现一些功能,例如:达成 ...

  4. kettle连接Hbase中数据导出(7)

    http://wiki.pentaho.com/display/BAD/Extracting+Data+from+HBase+to+Load+an+RDBMS 1)新建转换——Big Data——Hb ...

  5. Chapter 16_3 多重继承

    在Lua中进行面向对象编程时有几种方法,上一小结介绍了一种使用__index元方法的做法. 下面要介绍另一种方法,可以在Lua中实现多继承. 关键一点,在于用函数作为__index元字段. 多重继承意 ...

  6. oracle 导入sql中文乱码(转)

    导入sql的有中文,直接在linux环境下进行复制粘贴的,发现进去的都是乱码, 修改如下: 进入oracle用户,#vi /home/oracle/.bash_profile; 在最后一行添加:exp ...

  7. @ResponseBody返回json时,json数据丢失或者报错

    现象: 1.报错:There is a cycle in the hierarchy! 2.返回至前台的json不完整,字段丢失. 错误原因: eg:entity1的属性有list<entiti ...

  8. Oracle数据库插入数据出错:ORA-06550

    wpf应用调用oracle的存储过程,出错“ORA-06550:参数个数或参数类型出错”,如下图: 反复检查,存储过程的参数个数和参数类型都没错,觉得非常蹊跷.最后终于解决, 原因是当参数的值为nul ...

  9. java类中为什么设置set和get方法操作属性

    java程序规范中会建议大家尽量将类中的属性私有化,即定义为private变量,通过设置set和get函数来对属性进行操作.一些人存在这样的疑问,为什么不直接将属性设置为public,以后调用属性时直 ...

  10. 转载 deep learning:八(SparseCoding稀疏编码)

    转载 http://blog.sina.com.cn/s/blog_4a1853330102v0mr.html Sparse coding: 本节将简单介绍下sparse coding(稀疏编码),因 ...