Android Java使bitmapfactory图像可点击

Android Java使bitmapfactory图像可点击,java,android,Java,Android,好吧,那我该怎么做 我有两门课 PlayActivity.java 和 Play.java PlayActivity的setContentView是play.java 在play.java中,我有以下内容: gBall1 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans); gBall2 = BitmapFactory.decodeResource(getResources(), R.drawable.women

好吧,那我该怎么做

我有两门课

PlayActivity.java 和 Play.java

PlayActivity的setContentView是play.java

在play.java中,我有以下内容:

gBall1 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall2 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall3 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall4 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall5 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall6 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall7 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall8 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall9 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall10 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
gBall11 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall12 = BitmapFactory.decodeResource(getResources(), R.drawable.mantrans);
gBall13 = BitmapFactory.decodeResource(getResources(), R.drawable.womentrans);
这些都会出现在屏幕上


我如何才能使它们可点击并显示祝酒词?

您应该将这些位图设置为imageview,并将setOnClickListener添加到imageview


这样可以点击图像。

这里的基本前提是,在android中,只有视图是可点击的。在您的情况下,包含的各个位图是一个视图,因此,如果单击侦听器可以应用于任何内容,则必须在视图本身上执行。i:e位图只有放在视图(本例中为ImageView)中才能被单击

因此,我建议您让您的Play类扩展一个布局,如FrameLayout或LinearLayout。然后将所有位图添加到ImageView,并将ImageView添加到类中

 this.addView(childImageView)

在我的东西中,我让它们沿直线向下滚动,所以我不能用ImageView来实现这一点。在scrollView中获取整个视图,或者将其创建为imageView,将其放置在线性布局中,并将其放置在scrollView中。使线性布局垂直。