android 为什么子类滑动抽屉的高度表现不佳?

发布于 2024-11-17 06:23:23 字数 5069 浏览 3 评论 0原文

可能很简单,但我无法弄清楚这一点。

我有一个 SlidingDrawer 的子类,只是为了正确处理高度。
(感谢 @seydhe 提供解决方案)

问题是当我打开抽屉时高度设置不正确,
当我将手指从手柄按钮上抬起时,它就会固定。
在开始拉抽屉之前,如何使 SlidingDrawer 设置高度?

我尝试了各种组合 slidingDrawerRight.requestLayout(); 它有效。问题是我可以在哪里调用它? 我在很多地方都尝试过,比如
OnClickListener
OnTouchListener
OnDrawerCloseListener
但我无法让它工作。 也许有办法修复 xml 来做到这一点?

添加树图像和 xml。

如下面亲爱的图片nr:1所示,
我开始打开抽屉 并且大小不规则:

NR1: 打开时的图片..

 nr1 打开时的图片

NR2: Image when fully opened as soon as i let go of finger.

在此处输入图像描述

nr3 SD 背景设置为 #eeffae 且 RelativLayout 背景为 @null 时的图像

在此处输入图像描述

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

    <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/examplegallery" 
             android:layout_width="fill_parent"
             android:layout_height="wrap_content" />
   <RelativeLayout 
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >
    <Button 
        android:id="@+id/btn_newpen_drawtext" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pen"
    />      
    <EditText 
        android:id="@+id/etx_addtext_drawtext"
        android:layout_width="fill_parent"
        android:layout_toLeftOf="@+id/btn_delete_pen"
        android:layout_toRightOf="@+id/btn_newpen_drawtext"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="Enter text here"
    />
        <Button 
            android:id="@+id/btn_delete_pen" 
            android:layout_toLeftOf="@+id/btn_save_drawtext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Del"
        />
        <Button 
            android:id="@+id/btn_save_drawtext" 
            android:layout_alignParentRight="true" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="save"
        />

    </RelativeLayout>

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

    <com.bollen.sppik.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">

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

        <RelativeLayout 
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent"
            android:id="@+id/contentLayout2" 
            android:orientation="vertical" 
            android:background="#C0C0C0" 
            >

            <ImageButton android:id="@+id/btn_A" 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:text="Button_A" 
                android:background="@android:color/transparent" 
                android:src="@drawable/right_drawer"
                android:onClick="btnAListener">
            </ImageButton>

            <ImageButton android:id="@+id/btn_B" 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:layout_below="@+id/btn_A"
                android:text="Button_B" 
                android:background="@android:color/transparent" 
                android:src="@drawable/right_drawer"

                android:onClick="btnBListener">
            </ImageButton>          

        </RelativeLayout>
    </com.bollen.sppik.editimage.WrappingSlidingDrawer>
</LinearLayout>
</RelativeLayout>

Probably simple but i cannot figure this out.

I have a subclass of SlidingDrawer only to handle the hight correctly.
(thanks to @seydhe for the solution)

The problem is that when i open the drawer the hight is not set correctly,
It get set as soon as i lift my finger from the handle-butten.
How can i make the SlidingDrawer set the hight before i start pulling the drawer?

I have tries in various combinations to slidingDrawerRight.requestLayout();
and it works. The problem is where can i call it?
I have tried in various places like
OnClickListener
OnTouchListener
OnDrawerCloseListener
but i cannot get it to work.
Maybe there's a way to fix the xml to do this?

adding tree images and the xml.

As shown in down belove picture nr:1,
I start to open the drawer
and the size is irregular:

NR1: Image when being opened..

 nr1 Image when being opened

NR2: Image when fully opened as soon as i let go of finger.

enter image description here

nr3 Image when SD background is set to #eeffae and RelativLayout background is @null

enter image description here

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

    <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/examplegallery" 
             android:layout_width="fill_parent"
             android:layout_height="wrap_content" />
   <RelativeLayout 
        android:id="@+id/InnerRelativeLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >
    <Button 
        android:id="@+id/btn_newpen_drawtext" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pen"
    />      
    <EditText 
        android:id="@+id/etx_addtext_drawtext"
        android:layout_width="fill_parent"
        android:layout_toLeftOf="@+id/btn_delete_pen"
        android:layout_toRightOf="@+id/btn_newpen_drawtext"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="Enter text here"
    />
        <Button 
            android:id="@+id/btn_delete_pen" 
            android:layout_toLeftOf="@+id/btn_save_drawtext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Del"
        />
        <Button 
            android:id="@+id/btn_save_drawtext" 
            android:layout_alignParentRight="true" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="save"
        />

    </RelativeLayout>

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

    <com.bollen.sppik.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">

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

        <RelativeLayout 
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent"
            android:id="@+id/contentLayout2" 
            android:orientation="vertical" 
            android:background="#C0C0C0" 
            >

            <ImageButton android:id="@+id/btn_A" 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:text="Button_A" 
                android:background="@android:color/transparent" 
                android:src="@drawable/right_drawer"
                android:onClick="btnAListener">
            </ImageButton>

            <ImageButton android:id="@+id/btn_B" 
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:layout_below="@+id/btn_A"
                android:text="Button_B" 
                android:background="@android:color/transparent" 
                android:src="@drawable/right_drawer"

                android:onClick="btnBListener">
            </ImageButton>          

        </RelativeLayout>
    </com.bollen.sppik.editimage.WrappingSlidingDrawer>
</LinearLayout>
</RelativeLayout>

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

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

发布评论

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

评论(1

浅浅淡淡 2024-11-24 06:23:23

回答我自己的问题。
我将背景设置为透明,如下所示

android:background="@null" 

看起来不错,奇怪的调整大小行为仍然发生,但不可见。

answering my own question.
I set the background to transparent like this

android:background="@null" 

Looks ok and the odd resizing behavior still happens but it's not visible.

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