android中实现指针滑动的动态效果方法
<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属性来实现滚动的动画效果
HandlermyHandler=newHandler(){
@Override
publicvoidhandleMessage(Messagemsg){
//TODOAuto-generatedmethodstub
super.handleMessage(msg);
//对于c的更改和循环应该是在线程中跑,要不run仅仅执行一次,
zhizhen.setPadding(c,0,0,0);
}
};
classMyThreadextendsThread{
@Override
publicvoidrun(){
//发送一个消息,通知主线程改变UI
try{
while(c<=input){
c=c+1;
this.sleep(10);
myHandler.sendEmptyMessage(0);
}
}catch(InterruptedExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
相关文章
- android 置灰不可点击,Android Studio 运行按钮灰色的完美解决方法
- android系统开机画面_Android开机画面
- android bindservice方法,Android bindservice方法返回false
- 【Android FFMPEG 开发】C++ 回调 Java 方法 模板 ( JavaVM *vm | JNIEnv *env | jobject instance | 引用类型 | 模板代码示例 )
- 【Android 逆向】x86 汇编 ( 使用 IDA 解析 x86 架构的动态库文件 | 使用 IDA 打开动态库文件 | IDA 中查找指定的方法 )
- 【ijkplayer】编译 Android 版本的 ijkplayer ② ( 切换到 k0.8.8 分支 | 执行 init-android.sh 脚本进行初始化操作 )
- android默认时间格式修改方法
- android版本检测Android程序的版本检测与更新实现介绍
- Android工程内嵌资源文件的两种方法
- android全屏去掉title栏的多种实现方法
- 基于Android中手势交互的实现方法
- Android实现图片循环播放的实例方法
- Android使用Pull方法解析XML文件的方法
- Android实现永久保存数据的方法详解
- android自定义RadioGroup可以添加多种布局的实现方法
- android设置控件的颜色字体的方法
- android实现背景平铺的三种方法
- Android开发中的9个常见错误和解决方法
- Android入门之ActivityGroup+GridView实现Tab分页标签的方法
- Android提高之AudioRecord实现助听器的方法