How to achieve the dynamic effect of pointer sliding in android

Source: Internet
Author: User

Copy codeThe Code is as follows: <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 = "excellent"
Android: textSize = "12sp"/>

<TextView
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: gravity = "left"
Android: text = "good"
Android: textSize = "12sp"/>

<TextView
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: gravity = "left"
Android: text = "medium"
Android: textSize = "12sp"/>

<TextView
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: gravity = "left"
Android: text = "unhealthy"
Android: textSize = "12sp"/>

<TextView
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: gravity = "left"
Android: text = "toxic"
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>

The above code implementation layout is

First, because the pointer has a scroll bar under it, this is a framelayout layout. Second, to achieve constant pointer scrolling, You need to enable a thread to achieve the scrolling animation effect by controlling the padding attribute of the icon in which the pointer is located, using loops and sleep of threads in the thread.

Copy codeThe Code is as follows: Handler myHandler = new Handler (){

@ Override
Public void handleMessage (Message msg ){
// TODO Auto-generated method stub
Super. handleMessage (msg );
// The change and loop of c should be run in the thread, or run only once,
Zhizhen. setPadding (c, 0, 0, 0 );
}

};
Class MyThread extends Thread {

@ Override
Public void run (){
// Send a message notifying the main thread to change the UI
Try {

While (c <= input ){
C = c + 1;
This. sleep (10 );
MyHandler. sendEmptyMessage (0 );
}

} Catch (InterruptedException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.