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

Android颜色选择器_颜色选择控件源代码下载

程序员文章站 2022-03-01 13:30:26
...

本Demo是使用的GBK编码的、简单的一个颜色拾取器、可选择用手指在屏幕上滑动选择颜色以及透明度、右边的长条可以显示选中的颜色、上下滑动右边的长条可以修改所选取颜色的透明度、项目注释的代码并不多、但是在每个方法的用处都是注释了的、相信使用起来问题也不大、其实就是一个自定义的view类、直接拿来调用就行了

Android颜色选择器_颜色选择控件源代码下载


onMeasure方法

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
	int widthMode = MeasureSpec.getMode(widthMeasureSpec);
	int heightMode = MeasureSpec.getMode(heightMeasureSpec);
	int width = MeasureSpec.getSize(widthMeasureSpec);
	int height = MeasureSpec.getSize(heightMeasureSpec);
	if (widthMode == MeasureSpec.EXACTLY) {
		mWidth = width;
	} else {
		mWidth = 480;
	}
	if (heightMode == MeasureSpec.EXACTLY) {
		mHeight = height;
	} else {
		mHeight = 350;
	}
	LEFT_WIDTH = mWidth - SPLIT_WIDTH * 3 - RIGHT_WIDTH;
	setMeasuredDimension(mWidth, mHeight);
}


调用方法

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
	xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.px.color.ColorPickerView
        android:layout_width="fill_parent"
        android:layout_height="350dip" />

</LinearLayout>


自定义View代码只贴出了部分、更多代码大家可以下载源代码分析一下、可以直接使用的

源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1dDk1JiT 密码: s1mm