效果图:
好了直接上代码:
1:先看布局文件:
<com.android.camera.ui.EffectSettingPopupModify xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/EffectSettingPopupWindow"
android:layout_width="491px"
android:layout_height="500px">
<RelativeLayout android:background="@drawable/floor"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/Title_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/effects"
android:textColor="#ffffff"
android:paddingLeft="15px"
android:layout_marginTop="8px"
android:textSize="@dimen/effect_title_size" />
<View
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="2px"
android:layout_below="@+id/Title_id"
android:alpha="0.8"
android:layout_marginTop="8px"
android:background="#7eff00" />
<!-- 1 -->
<ImageView
android:id="@+id/luminance_id"
android:layout_width="51px"
android:layout_height="51px"
android:layout_below="@+id/view"
android:background="@drawable/luminance"
android:layout_marginLeft="43px"
android:layout_marginTop="10px"
/>
<TextView
android:id="@+id/luminance_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/luminance_id"
android:layout_below="@+id/control01"
android:textColor="#ffffff"
android:text="@string/luminance_title" />
<LinearLayout
android:id="@+id/control01"
android:layout_alignTop="@+id/luminance_id"
android:layout_toRightOf="@+id/luminance_id"
android:layout_marginLeft="30px"
android:layout_width="350px"
android:layout_height="60px"
android:orientation="horizontal"
android:gravity="center"
>
<SeekBar
android:id="@+id/SeekBar01"
android:layout_width="fill_parent"
android:layout_height="40px"
android:maxHeight="40px"
android:minHeight="40px"
android:max="100"
android:progress="50"
android:secondaryProgress="0"
android:progressDrawable="@drawable/effect_seekbar_style"
android:thumb="@drawable/slide_one"
android:thumbOffset="20px">
</SeekBar>
</LinearLayout>
<TextView
android:id="@+id/luminance_min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/control01"
android:layout_below="@+id/control01"
android:paddingLeft="28px"
android:textColor="#ffffff"
android:text="@string/luminance_min" />
<TextView
android:id="@+id/luminance_cent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/control01"
android:layout_marginLeft="280px"
android:textColor="#ffffff"
android:text="@string/luminance_cent" />
<TextView
android:id="@+id/luminance_max"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/control01"
android:layout_below="@+id/control01"
android:paddingRight="15px"
android:textColor="#ffffff"
android:text="@string/luminance_max" />
<!-- 2 -->
<ImageView
android:id="@+id/contrast_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/luminance_title"
android:src="@drawable/contrast"
android:layout_marginLeft="@dimen/effect_margin_left"
android:layout_marginTop="10px"/>
<TextView
android:id="@+id/contrast_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25px"
android:layout_below="@+id/control02"
android:textColor="#ffffff"
android:text="@string/contrast_title" />
<LinearLayout
android:id="@+id/control02"
android:layout_alignTop="@+id/contrast_id"
android:layout_toRightOf="@+id/contrast_id"
android:layout_marginLeft="30px"
android:layout_width="350px"
android:layout_height="60px"
android:orientation="horizontal"
android:gravity="center"
>
<SeekBar
android:id="@+id/SeekBar02"
android:layout_width="match_parent"
android:layout_height="40px"
android:maxHeight="40px"
android:minHeight="40px"
android:max="100"
android:progress="50"
android:secondaryProgress="0"
android:progressDrawable="@drawable/effect_seekbar_style"
android:thumb="@drawable/slide_one"
android:thumbOffset="20px" >
</SeekBar>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/control02"
android:layout_below="@+id/control02"
android:paddingLeft="28px"
android:textColor="#ffffff"
android:text="@string/luminance_min" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/control02"
android:layout_marginLeft="280px"
android:textColor="#ffffff"
android:text="@string/luminance_cent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/control02"
android:layout_below="@+id/control02"
android:paddingRight="15px"
android:textColor="#ffffff"
android:text="@string/luminance_max" />
<!-- 3 -->
<ImageView
android:id="@+id/saturation_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/contrast_title"
android:src="@drawable/saturation"
android:layout_marginLeft="43px" />
<TextView
android:id="@+id/saturation_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25px"
android:layout_below="@+id/control03"
android:textColor="#ffffff"
android:text="@string/saturation_title" />
<LinearLayout
android:id="@+id/control03"
android:layout_alignTop="@+id/saturation_id"
android:layout_toRightOf="@+id/saturation_id"
android:layout_marginLeft="30px"
android:layout_width="350px"
android:layout_height="60px"
android:orientation="horizontal"
android:gravity="center"
>
<SeekBar
android:id="@+id/SeekBar03"
android:layout_width="match_parent"
android:layout_height="40px"
android:maxHeight="40px"
android:minHeight="40px"
android:max="100"
android:progress="50"
android:secondaryProgress="0"
android:progressDrawable="@drawable/effect_seekbar_style"
android:thumb="@drawable/slide_one"
android:thumbOffset="20px">
</SeekBar>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/control03"
android:layout_below="@+id/control03"
android:paddingLeft="28px"
android:textColor="#ffffff"
android:text="@string/luminance_min" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/control03"
android:layout_marginLeft="280px"
android:textColor="#ffffff"
android:text="@string/luminance_cent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/control03"
android:layout_below="@+id/control03"
android:paddingRight="15px"
android:textColor="#ffffff"
android:text="@string/luminance_max" />
<!-- 4 -->
<ImageView
android:id="@+id/acutance_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/saturation_title"
android:src="@drawable/acutance"
android:layout_marginLeft="43px"/>
<TextView
android:id="@+id/acutance_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/acutance_id"
android:layout_below="@+id/control04"
android:textColor="#ffffff"
android:text="@string/acutance_title" />
<LinearLayout
android:id="@+id/control04"
android:layout_alignTop="@+id/acutance_id"
android:layout_toRightOf="@+id/acutance_id"
android:layout_marginLeft="30px"
android:layout_width="350px"
android:layout_height="60px"
android:orientation="horizontal"
android:gravity="center"
>
<SeekBar
android:id="@+id/SeekBar04"
android:layout_width="match_parent"
android:layout_height="40px"
android:maxHeight="40px"
android:minHeight="40px"
android:max="100"
android:progress="50"
android:secondaryProgress="0"
android:progressDrawable="@drawable/effect_seekbar_style"
android:thumb="@drawable/slide_one"
android:thumbOffset="20px">
</SeekBar>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/control04"
android:layout_below="@+id/control04"
android:paddingLeft="28px"
android:textColor="#ffffff"
android:text="@string/luminance_min" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/control04"
android:layout_marginLeft="280px"
android:textColor="#ffffff"
android:text="@string/luminance_cent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/control04"
android:layout_below="@+id/control04"
android:paddingRight="15px"
android:textColor="#ffffff"
android:text="@string/luminance_max" />
</RelativeLayout>
</com.android.camera.ui.EffectSettingPopupModify>
关键点:<SeekBar
android:id="@+id/SeekBar01"
android:layout_width="fill_parent"
android:layout_height="40px"
android:maxHeight="40px"
android:minHeight="40px"
android:max="100"
android:progress="50"
android:secondaryProgress="0"
android:progressDrawable="@drawable/effect_seekbar_style"
android:thumb="@drawable/slide_one"
android:thumbOffset="20px">
</SeekBar>
看看这个style:android:progressDrawable="@drawable/effect_seekbar_style"
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@android:id/background"
android:drawable="@drawable/slip_line_normal"/>
<item
android:id="@android:id/progress"
android:drawable="@drawable/slip_line_green"/>
<item
android:id="@android:id/secondaryProgress"
android:drawable="@drawable/slip_line_green"/>
</layer-list>
好了布局就已经完成了,只要在Activity里面继承implements SeekBar.OnSeekBarChangeListener 实现几个方法去改变响应的值就ok,是不是很简单呀!
上代码看看吧:
public class EffectSettingPopupModify extends RotateLayout implements SeekBar.OnSeekBarChangeListener {
private OnPreferenceChangedListener mListener;
protected CameraPicker mCameraPicker;
private SeekBar seekBar01,seekBar02,seekBar03,seekBar04;
private ComboPreferences mPreferences;
private final int MAX = 2;
private final int SEC_MAX = 1;
private final int MIDDLE = 0;
private final int SEC_MIN = -1;
private final int MIN = -2;
private int value_temp;
public void setListener(OnPreferenceChangedListener listener) {
mListener = listener;
if (mCameraPicker != null) mCameraPicker.setListener(listener);
}
public EffectSettingPopupModify(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public void initEffectSettingPopupModify(ComboPreferences preferences){
mPreferences = preferences;
}
private SeekBar[] mSeekBar = new SeekBar[4];
public void setSeekBar(int which,String progress){
int temp = Integer.valueOf(progress);
switch(temp){
case MAX:
mSeekBar[which].setProgress(100);
break;
case SEC_MAX:
mSeekBar[which].setProgress(75);
break;
case MIDDLE:
mSeekBar[which].setProgress(50);
break;
case SEC_MIN:
mSeekBar[which].setProgress(25);
break;
case MIN:
mSeekBar[which].setProgress(0);
break;
}
}
private final String[] value = new String[]{"-2","-1","0","1","2"};
private String getValue(int progress){
int temp = progress/25;
return value[temp];
}
@Override
protected void onFinishInflate() {
// TODO Auto-generated method stub
super.onFinishInflate();
seekBar01 = (SeekBar) this.findViewById(R.id.SeekBar01);
seekBar02 = (SeekBar) this.findViewById(R.id.SeekBar02);
seekBar03 = (SeekBar) this.findViewById(R.id.SeekBar03);
seekBar04 = (SeekBar) this.findViewById(R.id.SeekBar04);
seekBar01.setOnSeekBarChangeListener(this);
seekBar02.setOnSeekBarChangeListener(this);
seekBar03.setOnSeekBarChangeListener(this);
seekBar04.setOnSeekBarChangeListener(this);
mSeekBar[0] = seekBar01;
mSeekBar[1] = seekBar02;
mSeekBar[2] = seekBar03;
mSeekBar[3] = seekBar04;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
switch(seekBar.getId()){
case R.id.SeekBar01:
value_temp = progress;
mPreferences.edit().putString(CameraSettings.KEY_BRIGHTNESS, getValue(value_temp)).commit();
break;
case R.id.SeekBar02:
value_temp = progress;
mPreferences.edit().putString(CameraSettings.KEY_CONTRAST, getValue(value_temp)).commit();
break;
case R.id.SeekBar03:
value_temp = progress;
mPreferences.edit().putString(CameraSettings.KEY_SATURATION, getValue(value_temp)).commit();
break;
case R.id.SeekBar04:
value_temp = progress;
mPreferences.edit().putString(CameraSettings.KEY_SHARPNESS, getValue(value_temp)).commit();
break;
}
mListener.onSharedPreferenceChanged();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
switch(seekBar.getId()){
case R.id.SeekBar01:
mPreferences.edit().putString(CameraSettings.KEY_BRIGHTNESS, getValue(value_temp)).commit();
break;
case R.id.SeekBar02:
mPreferences.edit().putString(CameraSettings.KEY_CONTRAST, getValue(value_temp)).commit();
break;
case R.id.SeekBar03:
mPreferences.edit().putString(CameraSettings.KEY_SATURATION, getValue(value_temp)).commit();
break;
case R.id.SeekBar04:
mPreferences.edit().putString(CameraSettings.KEY_SHARPNESS, getValue(value_temp)).commit();
break;
}
mListener.onSharedPreferenceChanged();
}
}