滚动视图内的glsurfaceview,移动但不剪切

时间:2011-02-27 17:07:57

标签: android android-layout scrollview clipping glsurfaceview

我有一个内部线性布局的滚动视图。这个线性布局中的一个元素是glsurfaceview。

这一切都正常工作,当我滚动glsurfaceview上下移动时,然而当glsurfaceview到达应该被剪辑的滚动视图的顶部或底部时,它不是并且继续在滚动视图之外。这个截图应该更清楚:

glsurfaceview not clipped correctly

不要认为它是完全无关紧要的,但这是我的layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"
android:padding="6dip"
>
<ScrollView
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
>
    <LinearLayout
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"
    >
        <LinearLayout
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"
        >
            <LinearLayout
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:orientation="vertical"
            android:layout_weight="1"
            >
            <!-- LOTS OF SEEKBARS/TEXTVIEWS -->
            </LinearLayout>
            <LinearLayout
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:layout_weight="1.4"
                android:layout_marginRight="10dip"
                android:layout_marginLeft="10dip"
                android:orientation="horizontal" >
                <android.opengl.GLSurfaceView android:id="@+id/glview"  
                android:layout_width="100px"
                android:layout_height="250px"/>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
        android:layout_marginTop="6dip"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1"
        android:orientation="horizontal" >
            <!-- OK/CANCEL BUTTONS -->
        </LinearLayout>
    </LinearLayout>
</ScrollView>
</LinearLayout>

所有帮助非常感谢:)

3 个答案:

答案 0 :(得分:4)

目前不支持在ScrollView(或Listview等)中托管SurfaceViews。

答案 1 :(得分:0)

答案与支持无关。问题的原因是GLSurfaceView不在视图级别。简而言之:对于您来说,您在第一级拥有GLSurfaceView,然后在视图holes 中带有GLSurfaceView的其他视图(由Windows Manager处理,并且在哪里重要您将GLSurfaceView放在xml上,无论如何,它将放在第一级,而其他视图则放在下一级)

因此,您需要的是强制视图更新,并且可以解决此问题:您应在两个GLSurfaceView之间插入GLSurfaceViews或(FrameLayouts的RecyclerView)滚动。像这样的东西:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout   
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

     <ScrollView
        android:fillViewport="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

       ---- here should be linear layout with your glView, or RecyclerView instead if required ----
     </ScrollView>

   --- this frame also required: ---
   <FrameLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/transparent" />

</FrameLayout>

答案 2 :(得分:0)

您可以使用以下几行内容来消除过度滚动:

glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
glView.setZOrderOnTop(true);
glView.setZOrderMediaOverlay(true); 

并用于去除黑色背景:

linearLayout.setBackgroundColor(context.getResources().getColor(R.color.white));
linearLayout.addView(glView);

还要在清单文件中添加以下行:

android:hardwareAccelerated="true"