【问题标题】:Implement a ImageView to a SurfaceView将 ImageView 实现为 SurfaceView
【发布时间】:2012-02-14 23:00:42
【问题描述】:

我有一个小问题...

是否可以在SurfaceView 中实现ImageView, 或在SurfaceView 内创建ImageView

如果是这样,有人可以为我指出正确的方向。

【问题讨论】:

    标签: java android imageview surfaceview implements


    【解决方案1】:

    不,您不能将子 Views 添加到 SurfaceView

    您可以将ImageViewSurfaceView 都放在其他容器中,并且某些容器(RelativeLayoutFrameLayout)允许后面的子元素浮在前面的子元素之上(Z 轴排序)。因此,您可以通过这种方式在SurfaceView 中赋予ImageView 的视觉外观。

    【讨论】:

    • 有没有办法在代码中做到这一点,感谢您的帮助。
    • @toggy-tog-togs:将SurfaceView 放入XML 中的RelativeLayout。然后,在运行时,只需在RelativeLayout 上调用addView() 以添加您的ImageView,使用适当的RelativeLayout.LayoutParams
    • 你能告诉我如何处理添加到相对布局的视图上的点击监听器,因为它们不可点击。
    【解决方案2】:

    我在代码中使用 TextView 进行了此操作,但您可以使用 ImageView 更改文本视图。

    我的 TextView 是顶部的一个小条,因此参数不断变化。

          params = new LinearLayout.LayoutParams(
                   LinearLayout.LayoutParams.FILL_PARENT, 
               LinearLayout.LayoutParams.WRAP_CONTENT);
    
          LinearLayout layout = new LinearLayout(this);
          layout.setOrientation(LinearLayout.VERTICAL);
    
          TextView tv = new TextView(this);
          ourSurfaceView = new SurfGame(this);
    
            testbox = new LinearLayout.LayoutParams(widthx,heighty/30);
        layout.addView(tv,testbox);
        layout.addView(ourSurfaceView,params);
        setContentView(layout);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-05
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多