小编jbe*_*omy的帖子

使用Canvas制作可点击的位图

希望这是完成我的应用程序的最后一步.我需要在一个可点击的画布中制作一个位图,它将调用一个播放视频的新活动(mp4)或在当前活动中播放视频.

显示画布和位图的类是我反复使用的类,用于显示缩略图的完整图像.图像ID通过Intent传递.这是完整图像活动的代码(我非常喜欢菜鸟,并且使用这个网站和其他人一次一步拼凑我的代码,所以如果它不干净,我道歉):

public class full_image extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(new BitmapView(this));
    getWindow().setBackgroundDrawableResource(R.drawable.bground);
    getWindow().setWindowAnimations(0);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                           WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

class BitmapView extends View {
    public BitmapView(Context context) {
        super(context);
    }

    @Override
    public void onDraw(Canvas canvas) {
        int imgid = getIntent().getIntExtra("Full",0);
        Bitmap fullimage = BitmapFactory.decodeResource(getResources(),imgid);
        Bitmap playButton = BitmapFactory.decodeResource(getResources(), R.drawable.bt_play); //Added for Video
        Display display = getWindowManager().getDefaultDisplay();
        int fpWidth = fullimage.getWidth();
        int fpHeight = fullimage.getHeight();
        int playWidth = playButton.getWidth(); 
        int playHeight = playButton.getHeight(); …
Run Code Online (Sandbox Code Playgroud)

android canvas clickable

2
推荐指数
1
解决办法
5283
查看次数

标签 统计

android ×1

canvas ×1

clickable ×1