使用搜索栏混合两种颜色的最佳方法是什么?我的seekBar从中间开始,混合颜色显示在imageview(red1,green1blue1,red2green2,blue2的平均值)当搜索栏向左移动时,它应该向颜色移动(red1,green1,blue1,)然后如果向右移动它应该更多的颜色(red2,green2blue2)。这是我的代码希望我解释得很好。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.bignerdranch.android.colormixer.MixedColorScreen"
tools:showIn="@layout/activity_mixed_color_screen">
<SurfaceView
android:layout_width="match_parent"
android:layout_height="278dp"
android:background="#000000"
android:id="@+id/surfaceView3"></SurfaceView>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_below="@+id/surfaceView3"
android:layout_marginTop="57dp"
android:indeterminate="false"
android:progress="255"
android:max="510" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Your Color"
android:id="@+id/textView3"
android:layout_below="@+id/seekBar"
android:layout_centerHorizontal="true"
android:layout_marginTop="62dp" />
package com.bignerdranch.android.colormixer;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.SurfaceView;
import android.widget.SeekBar;
import android.widget.TextView;
public class MixedColorScreen extends AppCompatActivity {
private SeekBar mySeekBar;
private TextView seekText;
SurfaceView img;
private static final String TAG = "MYTAG";
private int red1,red2,green1,green2,blue1,blue2,
newRed,newGreen,newBlue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mixed_color_screen);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mySeekBar = (SeekBar) findViewById(R.id.seekBar);
seekText = (TextView) findViewById(R.id.textView3);
Intent i = getIntent();
red1 = i.getIntExtra("red1",150);
green1 = i.getIntExtra("green1",150);
blue1 =i.getIntExtra("blue1",150);
red2 = i.getIntExtra("red2",150);
green2 = i.getIntExtra("green2",150);;
blue2 = i.getIntExtra("blue2",150);
Log.i(TAG,"LOGING COLORS RED =" + red1 + red2 + "GREEN = " +
green1 + green2 + "BLUE = " + blue1 + blue2);
img = (SurfaceView) findViewById(R.id.surfaceView3);
newRed = (red1+red2)/2;
newGreen = (green1 +green2)/2;
newBlue = (blue1+blue2)/2;
Log.i(TAG,"RGB = " + newRed +" " + newGreen + " " + newBlue);
img.setBackgroundColor(Color.rgb(newRed, newGreen, newBlue));
mySeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Log.i(TAG,"ONPROGRESSCHANGES");
seekText.setText("SHOWING VALS- myprogres = " + mySeekBar.getProgress() + "/Max = " + mySeekBar.getMax() + "METHOD PROGRES = " + progress);
//red1,green1,blue1 ;
//red2,green2,blue2;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.i(TAG,"ONSTARTTRACHINGTOUCH");
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Log.i(TAG,"ONSTOPTRACKING");
}
});
}
}