效果图:
实现思路,用的自定义的控件,图片和按钮都是自己绘制的,并且附带点击事件,可以监听当前的旋钮的值:
第一步:先把布局写了:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#000000"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
/>
<LinearLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<com.example.longshine.zname.AnalogController
android:id="@+id/controllerBass"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000000" />
</LinearLayout>
</LinearLayout>
第二步:然后把自定义的控件类写了:AnalogController
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
/**
* Created by Harjot on 23-May-16.
*/
public class AnalogController extends View {
static float width, height;
float midx, midy;
Paint textPaint;
Paint circlePaint;
public Paint circlePaint2;