最近抽时间学习一下Android,做个笔记:

布局xml:

   <LinearLayout
android:id="@+id/date_label"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:background="@layout/slipercornerenable"
android:gravity="right|center"
android:padding="1dp" > <LinearLayout
android:layout_width="18dp"
android:layout_height="18dp"
android:background="@layout/slipercircle" >
</LinearLayout>
</LinearLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = View.inflate(this, layout.listview_select_date, null);
//设置两个选项的监听
view.findViewById(id.date_label).setOnClickListener(this);
view.findViewById(id.auto_update_date).setOnClickListener(this); }

切换方法:

    void switchControl(View view) {
LinearLayout llLayout = (LinearLayout) view;
int tag = 0;
if (view.getTag() != null) {
tag = Integer.parseInt(view.getTag().toString());
}
if (tag == 0) {
// 打开
view.setTag(1);
view.setBackgroundResource(layout.slipercornerenable);
llLayout.setGravity(Gravity.RIGHT);
} else {
// 关闭
view.setTag(0);
view.setBackgroundResource(layout.slipercornerdisenable);
llLayout.setGravity(Gravity.LEFT);
}
}

实现onClick事件:

    @Override
public void onClick(View arg0) {
int cid = arg0.getId();
switch (cid) {
case id.date_label:// 日期标签
switchControl(arg0);
return;
case id. auto_update_date:// 自动同步日期
switchControl(arg0);
return;
default:
break;
}
super.onClick(arg0);
}

开发中效果:

运行效果:

【Android】实现打开关闭效果的更多相关文章

  1. Android蓝牙----打开,关闭操作

    ① 我们先在AndroidManifest里面增加我们的Bluetooth权限 <uses-permission android:name="android.permission.BL ...

  2. 【转】Android 当打开“开发者模式”中的“不保留活动”后,程序应当怎么保持正常运行

    当打开这个设置以后,程序的Activity会自动销毁,每次返回的时候就会不断重oncreate,此时伴随的问题多多. 参考文档:http://www.bubuko.com/infodetail-960 ...

  3. android之打开网页

    首先改写strings.xml文件 代码如下: <resources> <string name="app_name">Intent应用</strin ...

  4. activity的打开关闭动画

    Activity的打开关闭或者说相互跳转之间可以设置动画的.默认的打开关闭直接消失或出现,比较不优美,但是有的手机Rom对这个默认做了修改,比如红米HM1,默认的就是新页面自右向左滑动出现,自左向右滑 ...

  5. Android 当打开“开发人员模式”中的“不保留活动”后,程序应当怎么保持正常执行

    Android 当打开"开发人员模式"中的"不保留活动"后,程序应当怎么保持正常执行咧. .? 在这几天,我一直在纠结这个问题.从发现,程序出现这个问题,是由于 ...

  6. 两行代码搞定Android视图扩散切换效果

    用最简单的方式来实现Android视图扩散切换效果. 一.概述 这两天时间动手撸了个视图扩散切换效果的控制器,API兼容至Android4.0,更方便我们在视图切换过程中有炫酷的过渡效果.本来是想实现 ...

  7. Android CameraX 打开摄像头预览

    目标很简单,用CameraX打开摄像头预览,实时显示在界面上.看看CameraX有没有Google说的那么好用.先按最简单的来,把预览显示出来. 引入依赖 模块gradle的一些配置,使用的Andro ...

  8. 通过暗码去打开/关闭usb debug开关

    通过暗码去打开/关闭usb debug开关 通过暗码去打开/关闭usb debug开关1. Description2. Analysis3. Solution4. Summary 1. Descrip ...

  9. CentOS7使用firewalld打开关闭防火墙与端口(转载)

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...

随机推荐

  1. Silverlight类百度文库在线文档阅读器

    百度文库阅读器是基于Flash的,用Silverlight其实也可以做. 我实现的在线阅读器可以应用于内网文档发布,在线阅览审批等.没有过多的堆积功能,专注于核心功能.主要有以下特性: 1. 基于XP ...

  2. 创建redis集群

    假设你已经安装好了redis ,如果还没有请安装 将多个实例跑起来 创建一个目录,比如 redis-cluster 把redis-server拷贝到这个目录下 在目录下为每一个实例创建一个文件夹 在每 ...

  3. iOS - UIButton设置文字标题下划线以及下划线颜色

    创建button设置可以折行显示 - (void)viewDidLoad { [super viewDidLoad]; UIButton * button = [[UIButton alloc] in ...

  4. PAT树_层序遍历叶节点、中序建树后序输出、AVL树的根、二叉树路径存在性判定、奇妙的完全二叉搜索树、最小堆路径、文件路由

    03-树1. List Leaves (25) Given a tree, you are supposed to list all the leaves in the order of top do ...

  5. matlab中patch函数的用法

    http://blog.sina.com.cn/s/blog_707b64550100z1nz.html matlab中patch函数的用法——emily (2011-11-18 17:20:33) ...

  6. 为什么使用spring

    现在基本的项目都会用到spring框架,那么我们为什么要使用spring呢?下面为大家总结一下,希望大家指正. spring是一个轻量级的容器框架,其核心是IOC(控制反转也叫依赖注入)和AOP(面向 ...

  7. 16.语句include和require的区别是什么?为避免多次包含同一文件,可用(?)语句代替它们?

    require->require是无条件包含也就是如果一个流程里加入require,无论条件成立与否都会先执行 require include->include有返回值,而require没 ...

  8. MVC中使用jquery uploadify上传图片报302错误

    使用jquery uploadify上传图片报302错误研究了半天,发现我上传的action中有根据session判断用户是否登录,如果没有登录就跳到登陆页,所以就出现了302跳转错误.原来更新了fl ...

  9. jqGrid APi 详解

    jqGrid APi 详解 jqGrid皮肤 从3.5版本开始,jqGrid完全支持jquery UI的theme.我们可以从http://jqueryui.com/themeroller/下载我们所 ...

  10. 用ssh整合时,用sessionfactory的getCurrentSession()获取不到session

    在用ssh整合时,一开始用的是getCurrentSession(),获取当前线程上的session,但是总是抛异常,不能获取. 后来用sessionfactory的openSession(),但是, ...