android 为什么子类滑动抽屉的高度表现不佳?
可能很简单,但我无法弄清楚这一点。
我有一个 SlidingDrawer 的子类,只是为了正确处理高度。
(感谢 @seydhe 提供解决方案)
问题是当我打开抽屉时高度设置不正确,
当我将手指从手柄按钮上抬起时,它就会固定。
在开始拉抽屉之前,如何使 SlidingDrawer 设置高度?
我尝试了各种组合 slidingDrawerRight.requestLayout();
它有效。问题是我可以在哪里调用它? 我在很多地方都尝试过,比如
OnClickListener
OnTouchListener
OnDrawerCloseListener
但我无法让它工作。 也许有办法修复 xml 来做到这一点?
添加树图像和 xml。
如下面亲爱的图片nr:1所示,
我开始打开抽屉 并且大小不规则:
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..
NR2: Image when fully opened as soon as i let go of finger.
nr3 Image when SD background is set to #eeffae and RelativLayout background is @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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答我自己的问题。
我将背景设置为透明,如下所示
看起来不错,奇怪的调整大小行为仍然发生,但不可见。
answering my own question.
I set the background to transparent like this
Looks ok and the odd resizing behavior still happens but it's not visible.