Code ในส่วนของ XML
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="wrap_content" android:id="@+id/rTxt" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:text="R : " android:layout_x="20dp" android:layout_y="10dp"> </TextView> <TextView android:layout_width="wrap_content" android:id="@+id/bTxt" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:text="B : " android:layout_x="20dp" android:layout_y="50dp" ></TextView> <TextView android:layout_width="wrap_content" android:id="@+id/gTxt" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:text="G : " android:layout_x="20dp" android:layout_y="90dp"> </TextView> <SeekBar android:id="@+id/rBar" android:layout_height="wrap_content" android:layout_x="55dp" android:layout_y="10dp" android:max="255" android:layout_width="240px"> </SeekBar> <SeekBar android:id="@+id/gBar" android:layout_height="wrap_content" android:layout_x="55dp" android:layout_y="50dp" android:max="255" android:layout_width="240px"> </SeekBar> <SeekBar android:id="@+id/bBar" android:layout_height="wrap_content" android:layout_x="55dp" android:layout_y="90dp" android:max="255" android:layout_width="240px"> </SeekBar> <TextView android:layout_width="250px" android:id="@+id/showColor" android:layout_height="250px" android:background="#FFFFFF" android:layout_x="37dp" android:layout_y="136dp"> </TextView> </AbsoluteLayout>
Code ในส่วนของ JAVA
package slayer.RGB; import android.app.Activity; import android.os.Bundle; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; public class RGBActivity extends Activity { private SeekBar rBar; private SeekBar gBar; private SeekBar bBar; private TextView showColor; private int rValue; private int gValue; private int bValue; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initView(); } private void initView() { rBar = (SeekBar)findViewById(R.id.rBar); rBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { // TODO Auto-generated method stub rValue = arg1; showResult(); } }); gBar = (SeekBar)findViewById(R.id.gBar); gBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { // TODO Auto-generated method stub gValue = arg1; showResult(); } }); bBar = (SeekBar)findViewById(R.id.bBar); bBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar arg0) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { // TODO Auto-generated method stub bValue = arg1; showResult(); } }); showColor = (TextView)findViewById(R.id.showColor); } private void showResult(){ showColor.setText("rVal : " + rValue + "\ngVal : " + gValue + "\nbVal : " + bValue); showColor.setBackgroundColor( 0xff000000 + rValue * 0x10000 + gValue * 0x100 + bValue ); } }
ไม่มีความคิดเห็น:
แสดงความคิดเห็น