I'm using android:bottomOffset to make the drawer stick out 100dip from the bottom. That works fine, but my content is not visible. It's only visible when I touch the drawer. How can I make that its always visible (the 100dip show the content)?
I first thought it's a visibility issue, because the visibility of the content is set to GONE in onFinishInflate()
, prepareContent()
, closeDrawer()
... copied the SlidingDrawer and removed these lines, didn't solve it. It seems that it is a position issue, currently I'm playing with the numbers but still don't find how to make the content appear where it should be... and don't have more time for this... any help is greatly appreciated.
Here's a pic of the problem for fast understanding:
I want that it looks like in the right part, from the beginning.
This default behaviour also looks erroneous to me, I don't know why somebody would want to make the offset only for the handle, making a gap between it and the content, and then on touch put the content directly under the handle...
Here is a working solution:
Create a full copy of SlidingDrawer class, and then replace the method dispatchDraw
so it looks like this:
@Override
protected void dispatchDraw(Canvas canvas) {
final long drawingTime = getDrawingTime();
final View handle = mHandle;
final boolean isVertical = mVertical;
drawChild(canvas, handle, drawingTime);
//if (mTracking || mAnimating) {
final Bitmap cache = mContent.getDrawingCache();
if (cache != null) {
if (isVertical) {
canvas.drawBitmap(cache, 0, handle.getBottom(), null);
} else {
canvas.drawBitmap(cache, handle.getRight(), 0, null);
}
} else {
canvas.save();
canvas.translate(isVertical ? 0 : handle.getLeft() - mTopOffset,
isVertical ? handle.getTop() - mTopOffset : 0);
drawChild(canvas, mContent, drawingTime);
canvas.restore();
}
//} else if (mExpanded) {
//drawChild(canvas, mContent, drawingTime);
//}
}
What I did was comment lines. As you see mContent, which is the content of the slider, only gets drawn when either mTracking, mAnimating or mExpanded is true, which is not the case while the slider is "closed". Probably the developers didn't have in mind a slider showing part of the content while "closed", so it didn't make any sense to draw the content while the slider is closed.
lxx's answers works flawlessly. I couldn't paste all code in response so I put another answer. Only difference than lxx's code is that I did not copy all SlidingDrawer class but extended it by making new class. Below is full code.
package com.localini.widget;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SlidingDrawer;
public class ExtendedSlidingDrawer extends SlidingDrawer {
private boolean mVertical;
private int mTopOffset;
public ExtendedSlidingDrawer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
int orientation = attrs
.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}
public ExtendedSlidingDrawer(Context context, AttributeSet attrs) {
super(context, attrs);
int orientation = attrs
.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}
@Override
protected void dispatchDraw(Canvas canvas) {
final long drawingTime = getDrawingTime();
final View handle = getHandle();
final boolean isVertical = mVertical;
drawChild(canvas, handle, drawingTime);
//if (mTracking || mAnimating) {
final Bitmap cache = getContent().getDrawingCache();
if (cache != null) {
if (isVertical) {
canvas.drawBitmap(cache, 0, handle.getBottom(), null);
} else {
canvas.drawBitmap(cache, handle.getRight(), 0, null);
}
} else {
canvas.save();
canvas.translate(isVertical ? 0 : handle.getLeft() - mTopOffset,
isVertical ? handle.getTop() - mTopOffset : 0);
drawChild(canvas, getContent(), drawingTime);
canvas.restore();
}
//} else if (mExpanded) {
//drawChild(canvas, mContent, drawingTime);
//}
}
}
In xml layout file you need to set e.g. android:buttonOffser="-100dip"
like explained in original question.