android中实现指针滑动的动态效果方法
发布时间:2023-10-07 15:54:44
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="2dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/up_icon"
android:layout_marginTop="0dp"
android:paddingTop="0dp" />
<LinearLayout
android:layout_width="240dip"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="7dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="优"
android:textSize="12sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="良"
android:textSize="12sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="中等"
android:textSize="12sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="不健康"
android:textSize="12sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:text="有毒害"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="240dip"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="7dp"
android:layout_marginTop="40dp"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="80"
android:textSize="12sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="120"
android:textSize="12sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="160"
android:textSize="12sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="200"
android:textSize="12sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="400"
android:textSize="12sp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/zhizhen"
android:id="@+id/zhizhen"/>
<ImageView
android:id="@+id/dengji_img"
android:layout_width="250dip"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:src="@drawable/dengji_icon" />
</FrameLayout>
上面这段代码实现的布局为
首先,因为指针有压着下面的滚动条,因此这是一个framelayout的布局。其次,要实现指针的匀速滚动,需要开启一个线程,在线程中能够实现利用循环,以及线程的休眠,通过控制指针所在图标的padding属性来实现滚动的动画效果
Handler myHandler =new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
//对于c的更改和循环应该是在线程中跑,要不run仅仅执行一次,
zhizhen.setPadding(c, 0, 0, 0);
}
};
class MyThread extends Thread{
@Override
public void run() {
//发送一个消息,通知主线程改变UI
try {
while(c<=input){
c=c+1;
this.sleep(10);
myHandler.sendEmptyMessage(0);
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


猜你喜欢
- 一、JMH vs JMeterJMeter可能是最常用的性能测试工具。它既支持图形界面,也支持命令行,属于黑盒测试的范畴,对非开发人员比较友
- using System; using System.IO; using System.Threading; using System.Wi
- 本文实例讲述了Android API开发之SMS短信服务处理和获取联系人的方法。分享给大家供大家参考,具体如下:Android API支持开
- 我们知道现在智能手机上都有这样一种功能,就是你在浏览图片的时候。不是硬性的点击按钮而是可以实现手指的拖动,划开效果。使用户具有更好的交互体验
- using System;using System.Collections.Generic;using System.Text;using
- (1)、在程序入口处,打开登录窗口 static void Main() { Application.EnableVisualStyles(
- 概述在平时开发过程中经常会碰到需要使用圆角button的情况,一般也会包括很多其他小功能,比如要在里面添加img,设置不同的圆角大小等。针对
- 本文所述为一个C#使用iCSharpcode压缩的使用类,经测试效果不错。分享给大家供大家参考之用。具体方法如下:1.参数类using Sy
- 这一篇博客我们来使用UGUI实现图片的拖拽功能。说到拖拽,那必然离不开坐标,UGUI 的坐标有点不一样,它有两种坐标,一种是屏幕坐标,还有一
- 本文实例为大家分享了ListView分页加载数据的具体代码,供大家参考,具体内容如下FenyeActivitypackage com.exa
- 一、settings.xml文件会在两个目录下存在:1、Maven安装目录(全局):%MAVEN_HOME%\conf\settings.x
- 一、使用无参构造方法创建二、使用静态工厂创建三、使用实例工厂创建来源:https://www.cnblogs.com/jock766/p/1
- 概述:EventBus是一款针对Android优化的发布/订阅事件总线。主要功能是替代Intent,Handler,BroadCast在Fr
- 一、创建线程启动线程—start 方法通过覆写 run 方法创建⼀个线程对象,但线程对象被创建出来并不意味着线程就开始运
- 本文实例为大家分享了Java实现动态数字时钟的具体代码,供大家参考,具体内容如下构建:Clock继承 JFrame 为运行页面ClockTe
- 一、Widget设计步骤需要修改三个XML,一个class:1.第一个xml是布局XML文件(如:main.xml),是这个widget的。
- mybatis多个区间处理如图:要实现车辆数不同区间查询条件思路a.前端传数组,数组里面放"1-5"String类型值
- 大家在银行交易某些业务时,都可以看到无论是身份证、银行账号中间部分都是用*号替换的,下面小编把代码整理如下:/// <summary&
- 导出Excel的框架有很多种,POI相对来说比较老了,很多Excel框架底层都是POI、有EasyPoi、EasyExcel、包括Hutoo
- 这篇文章主要介绍了Spring @Transactional注解失效解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的