android 如何将两个滑动抽屉处理程序放在一起

发布于 2024-11-28 01:42:31 字数 6509 浏览 4 评论 0原文

(我自己解决了)
需要一些关于如何执行此操作的建议。
为了澄清,我添加了两张图片,显示左侧的两个滑动抽屉。
它们默认是重叠的,所以我将一张图像更改为 android-icon 以更好地看到问题。

供参考
我正在使用由 Alessandro Crugnola 创建的这个抽屉自定义小部件 < /a>
对于我的两个抽屉,您可以在图像左侧看到。

我知道默认情况下处理程序是位置居中的并且需要建议 关于如何将它们垂直并排放置。 如图所示,他们必须占据孔屏。

我已经测试了layout_weight =“1”并将它们放入LinearLayout
但这给了我一个半尺寸的抽屉。我非常理解默认的 SliderDrawer 无法做到这一点,所以问题是什么样的黑客可以做到这一点。

有办法做到这一点吗?

"pic1"> pic2

(更新两个图像重叠时的外观,请参阅下面的讨论中的详细信息)

在此处输入图像描述 在此处输入图像描述 我的 XML:

    <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/imageEditGallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:spacing="2px"
        android:gravity="top"
        android:paddingTop="20dip"
    />
    <RelativeLayout
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <EditText
            android:id="@+id/etx_addtext_drawtext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="Enter text here"
        />

    </RelativeLayout>

    <com.bulk.sprise.editimage.SlidingDrawerLeftFriends
        xmlns:my="http://schemas.android.com/apk/res/com.bulk.sprise"
        android:id="@+id/sliding_drawer_left_friends"
        my:direction="leftToRight"
        android:layout_width="280dip"
        android:layout_height="wrap_content"
        my:handle="@+id/handleLeftFriends"
        my:content="@+id/content"

        >
        <include
            android:id="@id/content"
        layout="@layout/drawer_left_friends_content_editimage" />
        <ImageView
            android:id="@id/handleLeftFriends"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/drawer_left"
            android:topOffset="10dip"
        />
    </com.bulk.sprise.editimage.SlidingDrawerLeftFriends>

    <com.bulk.sprise.editimage.SlidingDrawerLeftOptions
        xmlns:my="http://schemas.android.com/apk/res/com.bulk.sprise"
        android:id="@+id/sliding_drawer_left_options"
        my:direction="leftToRight"
        android:layout_width="280dip"
        android:layout_height="wrap_content"
        my:handle="@+id/handleLeftOptions"
        my:content="@+id/content"
        >
        <include
            android:id="@id/content"
        layout="@layout/drawer_left_options_content_editimage" />
        <ImageView
            android:id="@id/handleLeftOptions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"
            android:topOffset="40dip"

        />
    </com.bulk.sprise.editimage.SlidingDrawerLeftOptions>



    <LinearLayout android:id="@+id/linearLayout_container_SlidingDrawerRight"
        android:layout_width="110dip"
        android:layout_height="wrap_content"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:visibility="visible"
        >

        <com.bulk.sprise.editimage.WrappingSlidingDrawer android:id="@+id/slidingDrawerRight"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:handle="@+id/slideHandleButtonRight"
            android:content="@+id/contentLayout2"
            android:orientation="horizontal"
            android:background="@null">

            <ImageButton android:id="@+id/slideHandleButtonRight"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/drawer_right"
                android:onClick="btnSlidingDrawerHandler">
            </ImageButton>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/contentLayout2"
                android:orientation="vertical"
                android:background="@null"

                >

                <ImageButton android:id="@+id/btn_A"
                    android:layout_height="60dip"
                    android:layout_width="60dip"
                    android:text="Button_A"
                    android:background="@android:color/transparent"
                    android:src="@drawable/plus_ball"
                    android:onClick="btnAListener"
                    android:gravity="right"
                    android:scaleType="fitXY">
                </ImageButton>

                <ImageButton android:id="@+id/btn_B"
                    android:layout_height="60dip"
                    android:layout_width="60dip"
                    android:layout_below="@+id/btn_A"
                    android:text="Button_B"
                    android:background="@android:color/transparent"
                    android:src="@drawable/text_ball"
                    android:gravity="right"
                    android:onClick="btnBListener"
                    android:scaleType="fitXY">
                </ImageButton>

                <ImageButton android:id="@+id/btn_C"
                    android:layout_height="60dip"
                    android:layout_width="60dip"
                    android:layout_below="@+id/btn_B"
                    android:text="Button_B"
                    android:background="@android:color/transparent"
                    android:src="@drawable/delete_ball"
                    android:gravity="right"
                    android:onClick="btnCListener"
                    android:scaleType="fitXY">
                </ImageButton>

            </RelativeLayout>
        </com.bulk.sprise.editimage.WrappingSlidingDrawer>
    </LinearLayout>
</RelativeLayout>

(solved by myself)
Need some advice on how to do this.
To clarify i Added two pictures showing the two slidingDrawers on the left side.
They are by default overlapping so i changed one image to the android-icon to see the problem better.

For reference
Im Using this Drawer custom widget created by Alessandro Crugnola
for my two drawer you see on the image left side.

I know by default the handler are position centered and need advice
on how to put them beside each other vertically.
They must take up hole screen as picture show.

I have tested layout_weight="1" and also putting them inside a LinearLayout
But that give me a half size drawer. I pretty much understand that the default
slidingdrawer cannot do this so the question is what kind of hack will do this.

Is there a way to do this?

pic1

pic2

(UPDATE WITH HOW IT CAN LOOK WHEN TWO IMAGES OVERLAP, se detail in discussion below)

enter image description here enter image description here
MY XML:

    <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/imageEditGallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:spacing="2px"
        android:gravity="top"
        android:paddingTop="20dip"
    />
    <RelativeLayout
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <EditText
            android:id="@+id/etx_addtext_drawtext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="Enter text here"
        />

    </RelativeLayout>

    <com.bulk.sprise.editimage.SlidingDrawerLeftFriends
        xmlns:my="http://schemas.android.com/apk/res/com.bulk.sprise"
        android:id="@+id/sliding_drawer_left_friends"
        my:direction="leftToRight"
        android:layout_width="280dip"
        android:layout_height="wrap_content"
        my:handle="@+id/handleLeftFriends"
        my:content="@+id/content"

        >
        <include
            android:id="@id/content"
        layout="@layout/drawer_left_friends_content_editimage" />
        <ImageView
            android:id="@id/handleLeftFriends"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/drawer_left"
            android:topOffset="10dip"
        />
    </com.bulk.sprise.editimage.SlidingDrawerLeftFriends>

    <com.bulk.sprise.editimage.SlidingDrawerLeftOptions
        xmlns:my="http://schemas.android.com/apk/res/com.bulk.sprise"
        android:id="@+id/sliding_drawer_left_options"
        my:direction="leftToRight"
        android:layout_width="280dip"
        android:layout_height="wrap_content"
        my:handle="@+id/handleLeftOptions"
        my:content="@+id/content"
        >
        <include
            android:id="@id/content"
        layout="@layout/drawer_left_options_content_editimage" />
        <ImageView
            android:id="@id/handleLeftOptions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"
            android:topOffset="40dip"

        />
    </com.bulk.sprise.editimage.SlidingDrawerLeftOptions>



    <LinearLayout android:id="@+id/linearLayout_container_SlidingDrawerRight"
        android:layout_width="110dip"
        android:layout_height="wrap_content"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:visibility="visible"
        >

        <com.bulk.sprise.editimage.WrappingSlidingDrawer android:id="@+id/slidingDrawerRight"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:handle="@+id/slideHandleButtonRight"
            android:content="@+id/contentLayout2"
            android:orientation="horizontal"
            android:background="@null">

            <ImageButton android:id="@+id/slideHandleButtonRight"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/drawer_right"
                android:onClick="btnSlidingDrawerHandler">
            </ImageButton>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/contentLayout2"
                android:orientation="vertical"
                android:background="@null"

                >

                <ImageButton android:id="@+id/btn_A"
                    android:layout_height="60dip"
                    android:layout_width="60dip"
                    android:text="Button_A"
                    android:background="@android:color/transparent"
                    android:src="@drawable/plus_ball"
                    android:onClick="btnAListener"
                    android:gravity="right"
                    android:scaleType="fitXY">
                </ImageButton>

                <ImageButton android:id="@+id/btn_B"
                    android:layout_height="60dip"
                    android:layout_width="60dip"
                    android:layout_below="@+id/btn_A"
                    android:text="Button_B"
                    android:background="@android:color/transparent"
                    android:src="@drawable/text_ball"
                    android:gravity="right"
                    android:onClick="btnBListener"
                    android:scaleType="fitXY">
                </ImageButton>

                <ImageButton android:id="@+id/btn_C"
                    android:layout_height="60dip"
                    android:layout_width="60dip"
                    android:layout_below="@+id/btn_B"
                    android:text="Button_B"
                    android:background="@android:color/transparent"
                    android:src="@drawable/delete_ball"
                    android:gravity="right"
                    android:onClick="btnCListener"
                    android:scaleType="fitXY">
                </ImageButton>

            </RelativeLayout>
        </com.bulk.sprise.editimage.WrappingSlidingDrawer>
    </LinearLayout>
</RelativeLayout>

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

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

发布评论

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

评论(3

临风闻羌笛 2024-12-05 01:42:31

我们将两个滑动抽屉命名为 sd1 和 sd2。解决这个问题的一个想法(未经测试)是为处理程序提供自定义图像,并让一个滑动抽屉 (sd1) 可见,而其他 (sd2) 隐藏(可见性设置为“消失”)。

然后,在您看来,在显示 sd1 处理程序的边缘,旁边有一个 sd2 处理程序图像的图像(按钮或普通图像)。这将使 UI 看起来像有 2 个滑动抽屉等待拉出。

所以现在,当用户拉出 sd1 时,它会按照设计工作。当他单击另一张图像时,sd2 可见并且被拉出。这样你就可以拥有两个滑动抽屉了。

这种方法的潜在复杂性是:
1. 未经测试
2. 您可能需要一个自定义视图,以使 sd2 处理程序图像恰好位于 sd1 处理程序旁边。
3. 在具有不同屏幕尺寸的不同设备上处理此方法可能会很棘手。

Lets call both sliding drawers sd1 and sd2. One idea (untested) to address this, would be to have custom images for the handler, and have one sliding drawer (sd1) visible, and other (sd2) hidden (with visibility set to "gone").

And then, in your view, right at the edge where the sd1 handler is displayed have an image (button or plain image) of sd2 handler image right next to it. This will make the UI seem like there are 2 sliding drawers waiting to be pulled out.

So now, when the user pulls out sd1 it works according to design. When he clicks the other image, that makes sd2 visible and it gets pulled out. That way you can have both sliding drawers.

Potential complication of this approach are:
1. Untested
2. You may need a custom view to have the sd2 handler image exactly next to sd1 handler.
3. Handling this approach on different devices with different screen sizes may be tricky.

我为君王 2024-12-05 01:42:31

哦,我们再次采用另一种可能的解决方案

如果我在 LinearLayout 中有两个滑动抽屉并将它们定位怎么办
layout_weight="1"layout_hight="0dip"

这将迫使他们平衡高度,我有两个抽屉
左侧垂直均匀分布。
当然,它们不会有完整的高度,但我不想使用它们
所以它们都有空的 dummy_layout.xml。

我想使用的是位置良好且均匀的处理程序图像。

现在,我将上面的问题 xml 代码也放入其中并 make
处理程序图像view.gone.something....

现在左侧侧板上有四个滑动抽屉。两个不可见,两个可见。
现在我有了两个抽屉处理程序的机制,它们
将在所有设备上正常工作。

我看到右边有两个抽屉。
如果我拉动它们,必须有某种方法将拉动重定向到我的
所需的全高抽屉隐藏在后面。

我认为人们可以将虚拟抽屉设置为不可见,但像往常一样拉动手柄。
通过这样做,会在下面的真实抽屉上触发一个 drawer.open()

也许我出路了,如果我错了,请纠正我。

你在关注吗..

oh here we go again with another possible solution

What if i have two slidingDrawer inside a LinearLayout and position them
with layout_weight="1" and layout_hight="0dip".

This will force them to even the hight and i have two drawers
evenly spaced vertically on the left side.
They will not have full hight of course but i dont want to use them
so they both have empty dummy_layout.xml.

What i want to use is there nicely and evenly positioned handler images.

now, I take my question xml code above and put that in as well and make
the handler images view.gone.something....

Now there ar four slidingdrawers on the left sida. Two invisible and two visible.
Now i have the mechanism for the two drawer handlers and they
will work on all devices right.

what i see is two drawers right.
If i pull them there must be some way to redirect the pull to my
desired full hight drawer hidden behind.

I think one could set the dummy-drawer invisible but pull the handel as usual.
By doing so trigger a drawer.open() on the real one underneath.

maybe im way-out there and please correct me if im wrong.

are you following..

幸福%小乖 2024-12-05 01:42:31

我自己设法让它工作。
这已经过测试并且适用于任何需要它的人。
尚未在不同屏幕尺寸上进行测试。

创建两个处理程序图像。
对于 hdpi,一个是 58x400,另一个是 58x132。
在大的一张上,将图形放在下部,以便顶部是透明的。
另一个图像处理程序必须看起来像普通处理程序。

只需在 xml 中安排两个 slipDawer 即可
较大的图像(slidingDrawer)首先出现。

您还需要在较小的处理程序上执行 BringToFront(),
如果 gui 发生变化,将其放在更大的处理程序后面

就是这样

Managed to get it working myself.
This is tested and working for anyone who need it.
Have not tested it on different screen sizes.

Create two handler images.
For hdpi one is 58x400 and the other is 58x132.
On the big one place the graphic on the lower part so the top part is transparent.
The other image handler must look like a normal handler.

just arrange your two slidingDawer's in the xml so that
the larger image(slidingDrawer) comes first.

Also you need to do bringToFront() on the smaller handler,
if gui changes place it behind the larger handler

That's it

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