我想在屏幕上有3个项目:SeekBar,Background img,Rotatable img。 任务:绘制2个图像:仪表和针,然后根据搜索栏进度旋转针。 我尝试上传到平板电脑时出现问题
07-10 09:52:13.680: E/AndroidRuntime(30494): java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.aaa.samples.thermometer/com.aaa.samples.meter.MeterActivity}:
java.lang.ClassCastException: com.aaa.samples.meter.MeterActivity cannot be cast to android.widget.SeekBar$OnSeekBarChangeListener
尝试了很多不同的设置与relativelayout等没有运气
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="150" />
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/spidometras" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/rodykle" />
</FrameLayout>
如果需要的话:
seekBar = (SeekBar)findViewById(R.id.seekBar1);
seekBar.setOnSeekBarChangeListener((OnSeekBarChangeListener) this);
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
ImageView img = (ImageView)findViewById(R.id.imageView1);
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.rodykle);
// Getting width & height of the given image.
int w = bmp.getWidth();
int h = bmp.getHeight();
// Setting post rotate to 90
Matrix mtx = new Matrix();
mtx.postRotate(progress);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
img.setImageDrawable(bmd);
}
});
}
答案 0 :(得分:1)
删除seekBar.setOnSeekBarChangeListener((OnSeekBarChangeListener) this);
行
仔细查看您的班级代码
下面一行:
seekBar.setOnSeekBarChangeListener((OnSeekBarChangeListener) this);
尝试将案例活动键入OnSeekBarChangeListener
,然后在下一行添加新的OnSeekBarChangeListener
。所以只需删除此行。
答案 1 :(得分:0)
听起来您生成的文件已损坏/未更新。 尝试去Project-&gt;干净。