Guide the circle on the page

Source: Internet
Author: User

Guide the circle on the page

Package com. zzw. drawable; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. util. attributeSet; import android. view. view; public class Circle extends View {private int posfirst = 0; // Number of circles private int count = 0; // use this constructor, otherwise, the public Circle (Context context, AttributeSet attrs) {super (context, attrs) ;}// you can set the number of circles to public void setCount (int) {count = a;} public void choose (int pos) {posfirst = pos; // execute this method to redraw this. invalidate () ;}@ Override protected void onDraw (Canvas canvas) {super. onDraw (canvas); Paint p = new Paint (); // remove the Sawtooth image to make the sphere smoother. setAntiAlias (true); // obtain the screen x y coordinate float w = getWidth (); float h = getHeight (); // the pitch of the sphere (screen adaptation for various models) int juli = (int) (w/7); // set the radius of the sphere (for screen adaptation of various models) float radius = w/50; for (int I = 0; I <count; I ++) {if (I = posfirst) {p. setColor (Color. RED); // draw a RED circle canvas. drawCircle (w-(count-1) * juli)/2 + juli * I, (float) (h * 0.9), radius + w/142, p );} else {p. setColor (Color. GRAY); // draw a GRAY circle canvas. drawCircle (w-(count-1) * juli)/2 + juli * I, (float) (h * 0.9), radius, p );}}}}

 

When using:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.zzw.imagedaohang.WelcomeActivity">    <android.support.v4.view.ViewPager        android:id="@+id/viewPager"        android:layout_width="match_parent"        android:layout_height="match_parent">    </android.support.v4.view.ViewPager>    <com.zzw.drawable.Circle        android:id="@+id/circle"        android:layout_width="match_parent"        android:layout_height="match_parent">    </com.zzw.drawable.Circle></RelativeLayout>

 

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.