2011-01-27 45 views
1

好吧,我不知道如何以一种体面的方式来说这个,所以我会提出它作为一个“你会怎么样?”。如何在gl中设计一个gridview

我有一个应用程序连接到一个服务,将所有数据连接到一个主要活动。活动由滑动抽屉分成两部分。在已经开始的活动中,只有一些按钮可以帮助您设置应用程序,并充当主菜单以便快速到达任何地方。

底部(通过抽屉点击显示)是应用程序的核心,一个显示9个长椅的gl窗口,每个长椅可容纳6个小部件。这些小部件显示有用的数据,并且必须能够自由移动和长时间打开选项菜单。

这就是我的问题所在,我使用gridview来存放小部件,但现在我使用GL作为长凳和触摸监听器,我不知道如何将gridview覆盖到长凳上并且仍然保持GL窗口的触摸运动,并仍然能够与gridview进行交互。

这让我要求任何人的思考如何去做这件事。在这一点上,我唯一的选择是弄清楚如何使gl中的所有小部件(即使有些甚至可能是条形图)。我宁愿不这样做,因为我不能很好地相互工作。但我真的无法弄清楚如何整合这些功能,并使其发挥功能。有任何想法吗?!

纸品加工GridView控件位图

此方法在我的扩展GridView控件(工作台)的。基本上我正在做的是通过一系列gridviews收集每个视图的位图,然后将位图设置为面板的纹理。

从工作台类

public Bitmap toBitmap() { 
    int x = getWidth(); 
    int y = getHeight(); 
    Bitmap b = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888); 
    Canvas canvas = new Canvas(); 
    canvas.setBitmap(b); 
    draw(canvas); 
    return b; 
} 

,这里的toBitmap是我的init的工作台

LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
for (int i = 0; i < mWB.length; i++) { 
    mWB[i] = mBoundService.createBench(ARMHomescreen.this, i+""); 
    mWB[i].setLayoutParams(lp); 
} 

请告诉我发生的事情是尺寸从来没有被设置的工作台,无论我是否使用LayoutParam或在toBitmap方法中设置大小...

回答

3

您可以使用常规布局来设计您的小部件。如果你的小部件可以很复杂,这当然是最好的事情。

不过的OpenGL不能做与Android布局什么,所以你对每个插件做的是:

  1. 含充气窗口小部件布局的私人查看。 (文本等)
  2. 关键点:绘制你的小部件到一个私人位图(使用View.draw(Canvas))。
  3. 转换位图到GL纹理渲染GL

显然,你只需要做#1一次,#2,#3,每次你的widget改变其显示的某些方面。

我已经将这种方法用于增强现实应用程序,该应用程序具有浮动在相机预览上的复杂布局,并且其工作得非常好。

后来补充:

这里是我的OpenGL叠加在相机预览背景屏幕捕获:

enter image description here

叠加物品被吸引到使用传统布局私人位图:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/mainlayout" 
    android:orientation="vertical" 
    android:layout_width="200dp" 
    android:layout_height="80dp" 
    android:background="@drawable/ar_regus_frame"> 

<TextView  
    android:id="@+id/text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:singleLine="false" 
    android:textColor="@android:color/black" 
    android:textSize="16sp" 
    android:textStyle="bold" 
    android:shadowColor="@android:color/white" 
    android:shadowDx="0" 
    android:shadowDy="1" 
/> 

<TextView  
    android:id="@+id/distance" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 
    android:layout_marginBottom="6dp" 
    android:background="@drawable/bkgnd_red_field" 
    android:textColor="@android:color/white" 
    android:textSize="16sp" 
    android:textStyle="bold" 
/> 

</RelativeLayout> 

有了这种技术,你享受最好的在这两个世界中...您可以使用Android的功能强大的布局系统来设计复杂的UI元素,并使用硬件加速OpenGL的速度和流畅性来渲染它们。

ADDED 2011年2月3日上午11:56 ISH

这里是你如何画一个以私人位图:

// Inflate the view 
View view = getLayoutInflater().inflate(R.layout.whatever, null); 

// HERE YOU SET ALL YOUR VIEW AND CHILD VIEW PROPERTIES, TEXT ETC 
// eg view.findViewById(R.id.foo).setSomeProperty(etc); 

// Now we set the desired pixel size of our view. This is something the framework 
// would normally do for you, as a result of the view being attached to the 
// Window's view hierarchy. Since *this* view is *not* attached to the Window, we 
// have to do it manually 
// NB: omitted DP to pixels conversion for clarity 
view.setLayoutParams(new LayoutParams(160, 160))); 
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); 
int width = view.getMeasuredWidth(); 
int height = view.getMeasuredHeight(); 
view.layout(0, 0, width, height); 

// Finally we draw our view to a private bitmap 
Canvas canvas = new Canvas(); 
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
canvas.setBitmap(bitmap); 
view.draw(canvas); 

// The bitmap can now be converted to a GL texture in the normal way. 
+0

这就是我的想法,只是创造了那么小部件的纹理和附加到飞机上,但我认为这将花费昂贵的小部件,每秒多次更改数据。您认为创建GridView的位图并更改纹理的次数可能是每秒20次,这是多么昂贵? – AedonEtLIRA 2011-01-31 20:21:57