欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

android中实现指针滑动的动态效果方法

程序员文章站 2023-12-12 19:14:40
复制代码 代码如下:

复制代码 代码如下:

<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>

上面这段代码实现的布局为
android中实现指针滑动的动态效果方法

首先,因为指针有压着下面的滚动条,因此这是一个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();
        }

上一篇:

下一篇: