安卓常用 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 ...
随机推荐
- 浙江大学 pat 题解---58
1058. A+B in Hogwarts (20) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue If you ...
- poj 3278 Catch That Cow bfs
Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...
- javascript动画效果之匀速运动(修订版)
在编写多块同时触发运动的时候,发现一个BUG, timer = setInterval(show, 30);本来show是一个自定义函数,当设为timer = setInterval(show(one ...
- D - 小Y上学记——要迟到了!
D - 小Y上学记——要迟到了! Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) ...
- ****ural 1141. RSA Attack(RSA加密,扩展欧几里得算法)
1141. RSA Attack Time limit: 1.0 secondMemory limit: 64 MB The RSA problem is the following: given a ...
- C# for循环嵌套
今天,我主要学习了for循环的嵌套. 第一个部分主要学习了打印直角在不同方向的三角形,求阶乘的和以及打印九九乘法表等. 例:打印直角在左下角的三角形. Console.WriteLine(" ...
- bootstrop之模态框关闭
1.js中操作$('#myModal5').map(function() {//用id选择器选中要关闭的模态框 $(this).modal('hide'); //关闭 }); 2.用button在模态 ...
- Centos7 设置DNS 服务器
在CentOS 7下,手工设置 /etc/resolv.conf 里的DNS,过了一会,发现被系统重新覆盖或者清除了.和CentOS 6下的设置DNS方法不同,有几种方式: 1.使用全新的命令行工具 ...
- JAVA常识积累
java Class<? extends Object> getClass() 这么写是什么意思 Class<? extends Object> 泛型Object以及Objec ...
- Strusts2--课程笔记4
类型转换器: Struts2默认情况下可以将表单中输入的文本数据转换为相应的基本数据类型.这个功能的实现,主要是由于Struts2内置了类型转换器.这些转换器在struts-default.xml中可 ...