安卓常用 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 ...
随机推荐
- js禁止浏览器后退,防止重复支付
<script language="JavaScript"> javascript:window.history.forward(1);</script>
- Oberon相关资源
http://www.michaelfranz.com/ http://en.wikipedia.org/wiki/Oberon_(programming_language) http://www.o ...
- Leetcode015 3Sum
public class S015 { public List<List<Integer>> threeSum(int[] nums) { Arrays.sort(nums); ...
- Visual Studio 2013 新增web项目IIS Express的64位版 转载来源http://www.cnblogs.com/jianyus/p/3524335.html
使用Visual Studio 2012开发SharePoint的应该都遇到过下面的错误“SharePoint 在32位进程中不受支持”,而怎么修改目标平台都不好使,因为VS 2012所配备的IIS ...
- Xcode7修改模块生成网络权限(ATS配置)
直接找 前往->前往文件夹->然后复制下面的路径填入框内,回车就能看到想要替换的文件夹了 /Applications/Xcode.app/Contents/Developer/Pla ...
- input[type=number]问题
有时候对于只能输入数字的表单会有想要写成input[type=number]但是其中有一个问题 <input type="text" name="code" ...
- js整频滚动展示效果(函数节流鼠标滚轮事件)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 3.Perl 多线程:Threads(exit thread_only)
还可以在导入threads模块时设置: use threads ('exit' => 'thread_only');
- iOS中控制器的释放问题
iOS中控制器的释放问题 ARC工程是可以重写dealloc方法并被系统调用的,但不需要手动调用父类的dealloc,手写[super dealloc]方法会报错,事实上系统会自动帮你调用父类的dea ...
- MAC图片格式转换
OS X下有一个sips的程序可以用来处理图片. sips的名称功能非常强大,参考 帮助文档 . 这里我们只用到其中的一个功能,转换图片格式. 命令参考: sips - s format jpeg ...