- 浏览: 674890 次
- 性别:
- 来自: 安徽
文章分类
- 全部博客 (252)
- Html/Div+CSS (12)
- Js/Jquery (34)
- Flex (2)
- Ajax (3)
- Java (35)
- C# (15)
- Spring (16)
- Hibernate (13)
- Struts2 (12)
- Struts1 (7)
- DWR (1)
- iBatis/myBatis (9)
- Tag(JSTL、EL) (1)
- Android (44)
- SQL (7)
- SEO (7)
- Exception (3)
- Tool (10)
- Other (3)
- WebService (9)
- Apache (7)
- Ext (0)
- Utils (12)
- thinking in programme (2)
- Hadoop (0)
- ActiveMQ (0)
- HTML5/CSS3 (0)
- WPF (1)
- NodeJs (1)
- 设计模式 (0)
- 程序人生 (1)
- 随笔 (1)
- Linux (1)
- Load Balance (0)
最新评论
-
drinkjava2:
太复杂了而且不通用,利用ThreadLocal可完美解决这一问 ...
JDBC的多条件动态查询 -
u013107014:
multipartRequest.getFiles(" ...
多文件上传 by MultipartFile and Multiple -
liyys:
可惜没讲你mysql数据库的表的设计
iBatis入门 -
Mapple_leave:
效果还是挺不错的,谢谢了。
中文简体与繁体的转换 -
arcpad:
JS禁用浏览器退格键
Android学习08-----Android中的基本控件(下)(7)_ZoomControls,PopupWindow,ExpandableListView
- 博客分类:
- Android
一、缩放控制: ZoomControls
Mian.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你好" android:textSize="10px" /> <ZoomControls android:id="@+id/zommcontrols" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="bottom" /> </LinearLayout>
ZoomControlsActivity.java
package com.iflytek.demo; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.TextView; import android.widget.ZoomControls; public class ZoomControlsActivity extends Activity { private ZoomControls zoomcontrols = null; private TextView text = null; private int size = 10; // 是保存文字大小 /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.zoomcontrols = (ZoomControls) super .findViewById(R.id.zommcontrols); this.text = (TextView) super.findViewById(R.id.text); this.zoomcontrols .setOnZoomInClickListener(new OnZoomInClickListenerImpl()); this.zoomcontrols .setOnZoomOutClickListener(new OnZoomOutClickListenerImpl()); } private class OnZoomInClickListenerImpl implements OnClickListener { @Override public void onClick(View v) { ZoomControlsActivity.this.size = size + 2; ZoomControlsActivity.this.text.setTextSize(size); } } private class OnZoomOutClickListenerImpl implements OnClickListener { @Override public void onClick(View v) { ZoomControlsActivity.this.size = size - 2; ZoomControlsActivity.this.text.setTextSize(size); } } }
二、弹出窗口: PopupWindow
PopupWindowActivity.java
package com.iflytek.demo; import android.app.Activity; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.PopupWindow; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; import android.widget.TextView; public class PopupWindowActivity extends Activity { private Button popbut = null; private TextView statusinfo = null; private View popView = null; private PopupWindow popWin = null; private RadioGroup changestatus = null; private Button cancel = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.popbut = (Button) super.findViewById(R.id.popbut); this.statusinfo = (TextView) super.findViewById(R.id.statusinfo); this.popbut.setOnClickListener(new OnClickListenerImpl()); } private class OnClickListenerImpl implements OnClickListener { @Override public void onClick(View v) { LayoutInflater inflater = LayoutInflater .from(PopupWindowActivity.this); PopupWindowActivity.this.popView = inflater.inflate( R.layout.popwindow, null); // 找到了布局文件中的View PopupWindowActivity.this.popWin = new PopupWindow( PopupWindowActivity.this.popView, 300, 220, true); PopupWindowActivity.this.changestatus = (RadioGroup) PopupWindowActivity.this.popView .findViewById(R.id.changestatus); // 取得弹出界面中的组件 PopupWindowActivity.this.cancel = (Button) PopupWindowActivity.this.popView .findViewById(R.id.cancel); PopupWindowActivity.this.changestatus .setOnCheckedChangeListener(new OnCheckedChangeListenerImpl()); PopupWindowActivity.this.cancel .setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupWindowActivity.this.popWin.dismiss(); // 不显示 } }); PopupWindowActivity.this.popWin.showAtLocation( PopupWindowActivity.this.popbut, Gravity.CENTER, 0, 0); } } private class OnCheckedChangeListenerImpl implements OnCheckedChangeListener { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { RadioButton but = (RadioButton) PopupWindowActivity.this.popView .findViewById(group.getCheckedRadioButtonId()); // 取得指定的单选钮被选中 PopupWindowActivity.this.statusinfo.setText("当前用户状态:" + but.getText().toString()); PopupWindowActivity.this.popWin.dismiss(); } } }
Main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/statusinfo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="当前用户状态:在线" /> <Button android:id="@+id/popbut" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="状态" /> </LinearLayout>
popwindow.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/popinfo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请选择您的当前状态:" android:textSize="20px" /> <RadioGroup android:id="@+id/changestatus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:checkedButton="@+id/online"> <RadioButton android:id="@+id/online" android:text="在线" /> <RadioButton android:id="@+id/offline" android:text="离线" /> <RadioButton android:id="@+id/stealth" android:text="隐身" /> </RadioGroup> <Button android:id="@+id/cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消"/> </LinearLayout>
三、树型组件: ExpandableListView
1 、组项监听
ExpandableListView02_Activity.java
package com.iflytek.demo; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.ExpandableListView.OnGroupClickListener; import android.widget.ExpandableListView.OnGroupCollapseListener; import android.widget.ExpandableListView.OnGroupExpandListener; import android.widget.Toast; public class ExpandableListView02_Activity extends Activity { private ExpandableListView elistview = null; private ExpandableListAdapter adapter = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.elistview = (ExpandableListView) super .findViewById(R.id.elistview); this.adapter = new MyExpandableListAdapter(this); this.elistview.setAdapter(this.adapter); this.elistview.setOnChildClickListener(new OnChildClickListenerImpl()); this.elistview.setOnGroupClickListener(new OnGroupClickListenerImpl()); this.elistview .setOnGroupExpandListener(new OnGroupExpandListenerImpl()); this.elistview .setOnGroupCollapseListener(new OnGroupCollapseListenerImpl()); } private class OnChildClickListenerImpl implements OnChildClickListener { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { Toast.makeText( ExpandableListView02_Activity.this, "子选项被选中,groupPosition = " + groupPosition + ",childPosition = " + childPosition, Toast.LENGTH_SHORT).show(); return false; } } private class OnGroupClickListenerImpl implements OnGroupClickListener { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { Toast.makeText(ExpandableListView02_Activity.this, "分组被选中,groupPosition = " + groupPosition, Toast.LENGTH_SHORT).show(); return false; } } private class OnGroupExpandListenerImpl implements OnGroupExpandListener { @Override public void onGroupExpand(int groupPosition) { Toast.makeText(ExpandableListView02_Activity.this, "打开分组,groupPosition = " + groupPosition, Toast.LENGTH_SHORT) .show(); } } private class OnGroupCollapseListenerImpl implements OnGroupCollapseListener { @Override public void onGroupCollapse(int groupPosition) { Toast.makeText(ExpandableListView02_Activity.this, "关闭分组,groupPosition = " + groupPosition, Toast.LENGTH_SHORT) .show(); } } }
MyExpandableListAdapter.java
package com.iflytek.demo; import android.content.Context; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.BaseExpandableListAdapter; import android.widget.TextView; public class MyExpandableListAdapter extends BaseExpandableListAdapter { // 一个组下肯定会有多个子选项 private String[] groups = new String[] { "我的好友", "家人", "同事", "黑名单" }; // 组名称 private String[][] children = new String[][] { { "赵一", "吴二", "张三", "李四" }, { "父亲", "母亲" }, { "王五", "赵六", "王八" }, { "票贩子", "造假商" } }; // 这里面定义的子选项 private Context context = null; public MyExpandableListAdapter(Context context) { this.context = context; } @Override public Object getChild(int groupPosition, int childPosition) { // 取得指定的子选项 return this.children[groupPosition][childPosition]; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } private TextView buildTextView() { AbsListView.LayoutParams params = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 55); TextView textView = new TextView(this.context); textView.setLayoutParams(params); textView.setTextSize(15.0f); textView.setGravity(Gravity.LEFT); textView.setPadding(70, 8, 3, 3); return textView; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { TextView textView = this.buildTextView(); textView.setText(this.getChild(groupPosition, childPosition).toString()); return textView; } @Override public int getChildrenCount(int groupPosition) { return this.children[groupPosition].length; } @Override public Object getGroup(int groupPosition) { return this.groups[groupPosition]; } @Override public int getGroupCount() { return this.groups.length; } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { TextView textView = this.buildTextView(); textView.setText(this.getGroup(groupPosition).toString()); return textView; } @Override public boolean hasStableIds() { return true; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } }
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ExpandableListView android:id="@+id/elistview" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
3 、上下文菜单
ExpandableListView03Activity.java
package com.iflytek.demo; import android.app.Activity; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.ExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnChildClickListener; import android.widget.ExpandableListView.OnGroupClickListener; import android.widget.ExpandableListView.OnGroupCollapseListener; import android.widget.ExpandableListView.OnGroupExpandListener; import android.widget.Toast; public class ExpandableListView03Activity extends Activity { private ExpandableListView elistview = null; private ExpandableListAdapter adapter = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.elistview = (ExpandableListView) super .findViewById(R.id.elistview); this.adapter = new MyExpandableListAdapter(this); this.elistview.setAdapter(this.adapter); super.registerForContextMenu(this.elistview); this.elistview.setOnChildClickListener(new OnChildClickListenerImpl()); this.elistview.setOnGroupClickListener(new OnGroupClickListenerImpl()); this.elistview .setOnGroupExpandListener(new OnGroupExpandListenerImpl()); this.elistview .setOnGroupCollapseListener(new OnGroupCollapseListenerImpl()); } private class OnChildClickListenerImpl implements OnChildClickListener { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { Toast.makeText( ExpandableListView03Activity.this, "子选项被选中,groupPosition = " + groupPosition + ",childPosition = " + childPosition, Toast.LENGTH_SHORT).show(); return false; } } private class OnGroupClickListenerImpl implements OnGroupClickListener { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { Toast.makeText(ExpandableListView03Activity.this, "分组被选中,groupPosition = " + groupPosition, Toast.LENGTH_SHORT).show(); return false; } } private class OnGroupExpandListenerImpl implements OnGroupExpandListener { @Override public void onGroupExpand(int groupPosition) { Toast.makeText(ExpandableListView03Activity.this, "打开分组,groupPosition = " + groupPosition, Toast.LENGTH_SHORT) .show(); } } private class OnGroupCollapseListenerImpl implements OnGroupCollapseListener { @Override public void onGroupCollapse(int groupPosition) { Toast.makeText(ExpandableListView03Activity.this, "关闭分组,groupPosition = " + groupPosition, Toast.LENGTH_SHORT) .show(); } } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; int type = ExpandableListView .getPackedPositionType(info.packedPosition); // 取得菜单项 int group = ExpandableListView .getPackedPositionGroup(info.packedPosition); // 取得所在组的索引 int child = ExpandableListView .getPackedPositionChild(info.packedPosition); // 取得子菜单项的索引 Toast.makeText(ExpandableListView03Activity.this, "type = " + type + ",group = " + group + ",child = " + child, Toast.LENGTH_SHORT).show(); } }
发表评论
-
This version of ADT requires android SDK
2013-07-25 16:45 1595Windows系统下用Eclipse开发工具开发An ... -
Android学习13-----网络通信(4) WebView组件
2012-11-27 09:18 2518WebView 是一个开发的浏览 ... -
Android学习13-----网络通信(3) 与Web Service进行通讯
2012-11-26 09:40 1896这里我们的WebService使用xFire开发。 ... -
Android学习13-----网络通信(2) 与Socket交换数据
2012-11-23 09:11 3309对于网络开发而言,最常用的交互模式:WebService、We ... -
Android学习13-----网络通信(1) 与WEB服务器交换数据
2012-11-22 09:11 2196与Web服务器交互: 如果手机要想与 web ... -
Android学习11-----多媒体技术(5) 媒体录制
2012-11-16 08:10 1896在Android中通过android.media ... -
Android学习11-----多媒体技术(4) 使用摄像头拍照,多点触控
2012-11-15 08:37 2889一、摄像头拍照 前面说媒体播放 时了解了 ... -
Android学习11-----多媒体技术(3) 媒体播放
2012-11-14 08:25 1415在 Androi ... -
Android学习11-----多媒体技术(2) Animation
2012-11-13 08:47 1997一、渐变动画, Tweened Animation ... -
Android学习11-----多媒体技术(1) 绘制简单图形,Bitmap,Matrix
2012-11-12 08:48 1626一、绘制简单图 ... -
Android学习12-----手机服务(4) 传感器
2012-11-19 09:13 2022传感器一般用于游戏中,在 Android 系统中为 ... -
Android学习12-----手机服务(1) 取得电池电量和声音服务:AudioManager
2012-11-18 11:18 3508一、取得电池电量信息 ... -
Android学习10-----Android组件通信 (8) 桌面显示组件:AppWidget
2012-11-02 08:36 2040一、 AppWidget 在使用 Androi ... -
Android学习10-----Android组件通信 (7) 广播机制:Broadcast
2012-11-01 08:43 1518一、 广播: 广播也是一种信息的发送机制,在 ... -
Android学习10-----Android组件通信 (6) PendingIntent
2012-10-31 08:20 2265Intent 的主要功能是表示用 ... -
Android学习10-----Android组件通信 (5) Service
2012-10-30 08:25 1740Service 基本组成: ... -
Android学习10-----Android组件通信 (4) 消息机制
2012-10-29 08:22 1554在 Android 操作系统中存在着消息队列的操作 ... -
Android学习10-----Android组件通信 (3) ActivityGroup
2012-10-26 08:23 2319导航栏在 Android 中的应用是很常见的,前面 ... -
Android学习10-----Android组件通信 (2) Activity生命周期
2012-10-25 08:16 1287Activity 是整个 Android 平台的基 ... -
Android学习10-----Android组件通信 (1) Intent
2012-10-24 08:43 2011在一个项目之中,会由多个 Activity ...
相关推荐
在Android开发中,控件是构建用户界面的基本元素,它们为用户提供交互操作的方式。这篇教程主要涵盖了九种常见的Android控件及其使用示例,包括ZoomControls、Include、VideoView、WebView、RatingBar、Tab、Spinner...
在大多数编程环境中,ZoomControls通常是一个派生自基础控件的类,例如Android中的ZoomControls继承自ViewGroup。这样的设计允许开发者利用已有的控件属性和方法,同时添加特定于缩放功能的特性。在学习ZoomControls...
首先,我们需要在布局文件(如activity_main.xml)中添加ZoomControls控件和ImageView控件,如下所示: ```xml ... android:id="@+id/layout"> android:id="@+id/image" ... /> <ZoomControls android:...
一般应用开发过程中,会在屏幕的右下角有两个缩放控件(缩小和放大),这个控件就是ZoomControls 如何使用其实现放大缩小功能: 1:首先在布局文件中配置ZoomControls控件 <ZoomControls android:id="@+id/...
### Android控件及布局的使用知识点详解 #### 第一章:Android基础 ...通过以上知识点的学习,开发者可以更深入地理解Android控件及布局的应用,并能够熟练地在自己的应用中使用这些控件来提升用户体验。
移动互联网应用
Android UI类继承关系图描述了Android开发中,用户界面组件之间的层次结构和继承关系。在Android开发中,UI组件构建在一种称为View的类之上,View又是Object的子类,构成了一个庞大的类体系。通过继承关系图,开发者...
在Android开发中,`View`是最基本的UI组件,所有可见的用户界面元素都是通过继承`View`类实现的。`View`类定义了控件的行为和外观,并且提供了绘制、布局、处理触摸事件等功能。本文档将详细介绍Android2.2版本中的`...
ZoomControls控件是一个可以缩放的控件,以下是它但一些主要但方法 hasFocus ():判断焦点 hide ():隐藏 onTouchEvent (MotionEvent event):现这个方法来处理触摸屏移动事件 setIsZoomInEnabled (boolean is...
在这个项目中,我们可能会看到`ZoomControls`类的实现,这是一个预定义的Android控件,用于提供简单的放大和缩小功能。`ZoomControls`通常用于地图应用或其他需要用户进行缩放操作的场景。 源码分析: 1. **...
默认情况下,我们在eclipse中拖动控件到editor中,控件的位置将位于整个屏幕的左上角。可以使用 android:layout_gravity、android:gravity和android:width三个属性值,实现控件的九宫格定位。 Xml代码 代码如下:...
在深入探讨ArcGIS Runtime SDK for Android的开发之前,我们首先需要理解GIS的基本概念。 GIS(Geographic Information System)是一种整合了地图、地理数据和计算能力的系统,用于捕捉、存储、管理、分析和展示...
【Android-GPS定位与Google地图管理模块的代码设计】这篇技术文档主要讲解了如何在Android平台上构建基于GPS定位和Google地图的导航系统。系统开发采用了Java语言和Eclipse开发工具,涉及的关键技术包括GPS定位、...
`MapView`是Android SDK中用于展示地图的控件,它是`MapView`类的实例,继承自`SurfaceView`。在`actMap`类中,我们看到`MapView`被初始化并添加到布局中。通过`findViewById()`方法获取到这个组件,并用它来设置...
4. ZoomControls控件。 ImageView/ImageButton控件属于非常简单的控件,我们就从这两个入手开始。剩余的控件和手机等移动设备关系比较紧密,我们随后看看基于移动设备有什么新特性的控件。本集的口号是“我的面子我...
在Android开发中,遵循一套规范是非常重要的,它能提高代码的可读性、可维护性和团队协作效率。以下是一些关键的Android开发规范和注意事项: **布局方面:** 1. **优先使用线性布局(LinearLayout)**,因为它简单...
通过研究这个`ZoomControls`类的源码,开发者可以学习到如何在Android上实现一个交互式的放大镜功能,这对于提高用户体验和开发生活类应用非常有帮助。同时,这也是一个很好的实践案例,可以帮助开发者加深对Android...
在Android平台上,地图功能是应用开发中的重要组成部分,它允许用户查看地理位置、导航以及执行其他与位置相关的操作。本文将详细探讨"Android Map"的相关知识点,包括地图的显示、缩放、位置查询以及如何实现个人...