在Android Widget中使用GestureOverlayView或类似的东西

时间:2013-03-14 18:05:38

标签: android widget gesture

是否可以创建一个包含GestureOverlayView的小部件?

我的目标是创建一个小部件,它在彼此的顶部有4个按钮堆栈,位于手势板的左侧。在我的活动和片段中,我目前正在使用GestureOverlayView,它允许我阅读手势,并将它们与保存的手势模式库相匹配,以确定特定的动作。

在项目的下一阶段,我想将我的片段和活动中的手势窗格复制到放置在Android主屏幕上的小部件上。

我读了一篇文章,说在Android中允许使用FrameLayouts,看看GestureOverlayView是如何从framelayout扩展的,我理想主义的自我认为这是可能的。

到目前为止,我已经获得了一个具有相同图像和布局的小部件,我希望使用它,它显示没有功能就好了。布局如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout_app"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".2"
        android:background="@drawable/draw_pad_background"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/call" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/text" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/app" />

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/contact" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".03"
        android:background="@drawable/button_divider"
        android:orientation="vertical" >

    </LinearLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight=".85" >

        <LinearLayout
            android:id="@+id/llSeparateLayer_app"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <!-- <LinearLayout android:layout_width="fill_parent" android:layout_height="1dip" 
                android:background="#FFFFFF" android:layout_centerVertical="true" /> <ImageView 
                android:layout_height="30dip" android:src="@drawable/call" android:layout_width="wrap_content" 
                android:scaleType="centerInside" android:layout_centerHorizontal="true" /> 
                <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" 
                android:layout_centerInParent="true"> <ImageView android:layout_height="30dip" 
                android:src="@drawable/text" android:layout_width="wrap_content" android:scaleType="centerInside" 
                android:layout_marginTop="30dip" /> </LinearLayout> -->

            <LinearLayout
                android:id="@+id/llOpenDSR"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight=".5"
                android:background="@drawable/draw_pad_background"
                android:gravity="center" >
            </LinearLayout>

        </LinearLayout>



    </RelativeLayout>

</LinearLayout>

如果我添加手势视图,它看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout_app"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".2"
        android:background="@drawable/draw_pad_background"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/call" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/text" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/app" />

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/contact" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight=".03"
        android:background="@drawable/button_divider"
        android:orientation="vertical" >

    </LinearLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight=".85" >

        <LinearLayout
            android:id="@+id/llSeparateLayer_app"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <!-- <LinearLayout android:layout_width="fill_parent" android:layout_height="1dip" 
                android:background="#FFFFFF" android:layout_centerVertical="true" /> <ImageView 
                android:layout_height="30dip" android:src="@drawable/call" android:layout_width="wrap_content" 
                android:scaleType="centerInside" android:layout_centerHorizontal="true" /> 
                <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" 
                android:layout_centerInParent="true"> <ImageView android:layout_height="30dip" 
                android:src="@drawable/text" android:layout_width="wrap_content" android:scaleType="centerInside" 
                android:layout_marginTop="30dip" /> </LinearLayout> -->

            <LinearLayout
                android:id="@+id/llOpenDSR"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight=".5"
                android:background="@drawable/draw_pad_background"
                android:gravity="center" >
            </LinearLayout>

        </LinearLayout>

        <android.gesture.GestureOverlayView
            android:id="@+id/appGestures"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:eventsInterceptionEnabled="false"
            android:fadeOffset="400"
            android:gestureColor="@color/default_gesture_color"
            android:gestureStrokeAngleThreshold="0.1"
            android:gestureStrokeLengthThreshold="80"
            android:gestureStrokeSquarenessThreshold="0.1"
            android:gestureStrokeType="multiple"
            android:orientation="horizontal"
            android:uncertainGestureColor="@color/default_gesture_color_uncertain" >

            <ImageView
                android:id="@+id/image_notification"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center" />

        </android.gesture.GestureOverlayView>

    </RelativeLayout>

</LinearLayout>

当我将此小部件添加到我的主屏幕时,我收到“问题加载小部件”

然后我找到了文档的这一部分:

“虽然小部件可以被理解为”迷你应用程序“,但在开始设计小部件之前,有一些重要的理解限制:

手势

由于小部件存在于主屏幕上,因此它们必须与在那里建立的导航共存。与全屏应用程序相比,这限制了窗口小部件中可用的手势支持。例如,虽然应用程序可能支持允许用户横向在屏幕之间导航的视图寻呼机,但是已经在主屏幕上执行该手势以便在主屏幕之间导航。

可用于小部件的唯一手势是:

触摸 垂直滑动“

http://developer.android.com/design/patterns/widgets.html

这是否意味着我无法使用此视图?

0 个答案:

没有答案