0

所以...我正在尝试填充一个 TextView,它根据活动顶部的红色、绿色和蓝色 SeekBars 的进度来扩展活动屏幕的整个下半部分。用户可以移动任何搜索栏,并且扩展活动下半部分的整个宽度和长度的 TextView 将使用正确的 RGB 配色方案填充,以匹配所有 3 个搜索栏的 1-100 移动。

关于如何做到这一点的任何想法?我已经用谷歌搜索了 Android 文档,但找不到我要找的东西。即使是让我知道该怎么做的链接也会很好:)

*我应该提到这里的代码在android VM上运行得很好

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity implements OnSeekBarChangeListener
{
    private SeekBar red;
    private SeekBar green;
    private SeekBar blue;

    private TextView progress1;
    private TextView progress2;
    private TextView progress3;


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        red = (SeekBar)findViewById(R.id.seekBar1);
        red.setOnSeekBarChangeListener(this);
        green = (SeekBar)findViewById(R.id.seekBar2);
        green.setOnSeekBarChangeListener(this);
        blue = (SeekBar)findViewById(R.id.seekBar3);
        blue.setOnSeekBarChangeListener(this);
        progress1 = (TextView)findViewById(R.id.textView2);
        progress2 = (TextView)findViewById(R.id.textView4);
        progress3 = (TextView)findViewById(R.id.textView6);     
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) 
    {
        switch(seekBar.getId())
        {
        case R.id.seekBar1:
        progress1.setText(""+progress); 
        break;  
        case R.id.seekBar2:
            progress2.setText(""+progress);
            break;
        case R.id.seekBar3:
            progress3.setText(""+progress);
            break;
        }       

    }

    @Override
    public void onStartTrackingTouch(SeekBar arg0) 
    {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStopTrackingTouch(SeekBar arg0) 
    {
        // TODO Auto-generated method stub

    }

}
4

1 回答 1

0

将 SeekBars 配置为最大值为 255,然后在您的onProgressChanged()使用中Color.argb()文档):

  int color = Color.argb(255, red.getProgress(), green.getProgress(), blue.getProgress());
  //you can also split that into the 3 channels if you wish
  //i'm assuming you actually want to show the resulting color
  progress1.setBackgroundColor(color);
于 2012-12-02T23:08:25.307 回答