Android:SlidingDrawer在SurfaceView下消失

发布于 2024-10-11 02:49:55 字数 2761 浏览 0 评论 0原文

我正在尝试在 FrameLayout 上创建一个包含 LinearLayout 内容的 SlidingDrawer 。

起初一切似乎都很好,我在屏幕底部找到了 SlidingDrawer 的句柄。 但是,如果我开始向上拖动手柄并且内容开始显示,它就会被手柄的边框矩形剪切。如果我一直向上拖动手柄,最终会显示整个内容,但是如果我现在向下拖动手柄,它将被内容的边框矩形剪切。另外,如果手柄一直向上,一旦我开始拖动它,整个内容就会消失。
我仍然可以单击手柄应该在屏幕上的位置,拖动它,内容就会显示,但我需要猜测手柄在哪里。

造成这种情况的原因似乎是我在 xml 文件中在 SlidingDrawer 之前有一个 SurfaceView。
从 xml 中删除视图可以解决这个问题,但是我需要这个视图。

这是 xml:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

    <!--  Removing this DrawView from here solves the problem -->
    <com.package.DrawView 
        android:id="@+id/main"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />

    <SlidingDrawer  
        android:id="@+id/SlidingDrawer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:allowSingleTap="true"
        android:animateOnClick="true"
        android:handle="@+id/slideHandleButton"
        android:content="@+id/contentLayout" 
        android:padding="10dip">

        <Button
            android:id="@+id/slideHandleButton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/sliding_button">
        </Button>

        <LinearLayout
            android:id="@+id/contentLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <Button 
                android:id="@+id/clearButton" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test">
            </Button>

        </LinearLayout>

    </SlidingDrawer>

</FrameLayout>   

Java:

package com.package;

import android.app.Activity;
import android.os.Bundle;

public class SlideTest extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
    }
}

package com.package;

import android.content.Context;
import android.util.AttributeSet;
import android.view.SurfaceView;

public class DrawView extends SurfaceView
{
    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
}

编辑:我刚刚注意到,如果 DrawView 扩展 View 而不是 SurfaceView,这个问题就会消失。 但是,我使用的是专用绘图线程,并且根据文档(和 LunarLander 示例),当使用专用绘图线程时,它应该绘制到 SurfaceView。

任何帮助将不胜感激!

I'm trying to create a SlidingDrawer with LinearLayout content over a FrameLayout.

At first it all seems fine, I get my SlidingDrawer's handle at the bottom of the screen.
But then, if I start dragging the handle up and the content starts showing, it gets clipped by the border rectangle of the handle. If I drag the handle all the way up the entire content eventually gets shown, however if I now drag the handle down, it will be clipped by the border rectangle of the content. Also, if the handle is all the way up, as soon as I start dragging it the whole content disappears.
I can still click on where the handle should be on the screen, drag it and the content would show, but I need to guess where the handle is.

What seems to be causing this is the fact that I have a SurfaceView in the xml file just before SlidingDrawer.
Removing the view from the xml solves this problem, however I need this view.

Here's the xml:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

    <!--  Removing this DrawView from here solves the problem -->
    <com.package.DrawView 
        android:id="@+id/main"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />

    <SlidingDrawer  
        android:id="@+id/SlidingDrawer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:allowSingleTap="true"
        android:animateOnClick="true"
        android:handle="@+id/slideHandleButton"
        android:content="@+id/contentLayout" 
        android:padding="10dip">

        <Button
            android:id="@+id/slideHandleButton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/sliding_button">
        </Button>

        <LinearLayout
            android:id="@+id/contentLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <Button 
                android:id="@+id/clearButton" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test">
            </Button>

        </LinearLayout>

    </SlidingDrawer>

</FrameLayout>   

Java:

package com.package;

import android.app.Activity;
import android.os.Bundle;

public class SlideTest extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
    }
}

package com.package;

import android.content.Context;
import android.util.AttributeSet;
import android.view.SurfaceView;

public class DrawView extends SurfaceView
{
    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
}

Edit: I just noticed that if DrawView extends View and not SurfaceView this problem goes away.
However, I'm using a dedicated drawing thread and according to the documentation (and LunarLander example) when using a dedicated drawing thread, it should draw to a SurfaceView.

Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

少年亿悲伤 2024-10-18 02:49:55

android:background="#00000000"

背景颜色是问题所在。

android:background="#00000000"

Background color was the problem.

你怎么这么可爱啊 2024-10-18 02:49:55

SurfaceView 的工作原理是在窗口上切一个“洞”以显示另一个表面(您绘制的表面)。这就是导致 SlidingDrawer 的抽屉被剪裁的原因。很抱歉,您无法同时使用这两种视图。

SurfaceView works by cutting a "hole" through the window to display another surface (the one you draw into.) This is what is causing the SlidingDrawer's drawer to be clipped. I'm sorry to say you won't be able to use both views together.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文