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>