安卓常用 widget
验证码
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的更多相关文章
- ios 和安卓常用图标、启动图 尺寸
---------------------------------------------ios---------------------------------------------------- ...
- odoo常用widget
widget=”statusbar” 头部状态条标签widget=”email” 电子邮件地址标签widget=”selection” 下拉选择标签widget=”mail_followers” ...
- 安卓常用的xml控件配件的使用包含shape,declare-styleable、selector
今天就讲我所遇到的常用到的一些通过xml文件制作的背景效果,以后用到的话就直接使用啦!哈哈,我一向就是这么懒! 接下来,就开始介绍了 1.shape的使用,可以混合使用 xml控件配置属性 andro ...
- odoo视图中常用widget
widget="statusbar" 头部状态条标签 widget="email" 电子邮件地址标签 widget="selection" ...
- Android的Context && 安卓常用系统服务(当前运行包名/当前网络状态和开关网络/音频服务/马达服务) (转)
转:http://blog.csdn.net/zhandoushi1982/article/details/8501773 Context字面意思上下文,位于framework 的android.co ...
- Android 常用开源代码整理
1.AndroidAnnotations一个强大的android开源注解框架, 基本上可以注入任何类型, 比一般的所谓的注入框架要快, 因为他是通过生成一个子类来实现的绑定.具体查看文档. 2.and ...
- 安卓TV开发(八) 移动智能终端多媒体爬虫技术 获取加载网页视频源
转载请标明出处:http://blog.csdn.net/sk719887916/article/details/40049137,作者:skay 从上一篇学习中,学习了多媒体技术中的怎么去用josu ...
- Flutter 即学即用系列博客——06 超实用 Widget 集锦
本篇文章我们来讲讲一些比较常用的 Widget. 大家验证的时候使用下面的代码替换 main.dart 代码,然后在 //TODO 语句返回下面常用 Widget 示例的代码. import 'pac ...
- Flutter常用插件
Dio Dio是一个强大的Dart Http请求库,支持Restful API.FormData.拦截器.请求取消等操作.视频中将全面学习和使用Dio的操作. Flutter_swiper swipe ...
随机推荐
- WEB前端组件思想【日历】
DEMO2: 思路:首先获取元素节点元素--->根据点击事件隐藏显示元素--->建立showdate方法(判断12月 则右边年份+1,月份1 )--->还要设置btn开关 防止多次重 ...
- Sublime themes/ lint themes setup
[Sublime 3 Setup for ES6 / Babel] https://www.youtube.com/watch?v=L8nmOqyyJLA [config oceanic next t ...
- SOJ 1210 二叉树
1210. 二叉树 Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description 在众多的数据结构中,二叉树是一种特殊而重要的结构,有 ...
- ASP.NET MVC 实现AJAX跨域请求的两种方法
通常发送AJAX请求都是在本域内完成的,也就是向本域内的某个URL发送请求,完成部分页面的刷新.但有的时候需要向其它域发送AJAX请求,完成数据的加载,例如Google. 在ASP.NET MVC 框 ...
- 创建 .gitignore 文件过滤规
文件 .gitignore 的格式规范如下: 所有空行或者以注释符号 # 开头的行都会被 Git 忽略. 可以使用标准的 glob 模式匹配. 匹配模式最后跟反斜杠(/)说明要忽略的是目录. 要忽略指 ...
- fatal error RC1004: unexpected end of file found处理方法
资源编译器错误 RC1004 错误消息 遇到意外的文件结束 此错误是由于文本文件的最后一行中缺少换行符和回车符而造成的.
- 调用Lua出错
错误提示:Could not load file or assembly 'lua51' or one of its dependencies. An attempt was made to load ...
- postgreSqL的序列sequence
PostgreSQL uses sequences to generate values for serial columns and serial columns are generally wha ...
- iOS的一些关键字
最近在使用Swift的过程中,感觉到苹果公司为了迎合Swift,在Objective-C中添加了许多关键字.这些关键字一般用来用来修饰属性,或者方法的参数以及方法的返回值等等.而在以前的Objecti ...
- Mysql CPU占用高的问题解决方法小结
通过以前对mysql的操作经验,先将mysql的配置问题排除了,查看msyql是否运行正常,通过查看mysql data目录里面的*.err文件(将扩展名改为.txt)记事本查看即可.如果过大不建议用 ...