read

You have to make a custom class that overrides the onMeasure() of SlidingDrawer, like this:

<pre class="default prettyprint" style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;">import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SlidingDrawer;

public class WrappingSlidingDrawer extends SlidingDrawer {

   
public WrappingSlidingDrawer(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 WrappingSlidingDrawer(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 onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

       
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
       
int widthSpecSize =  MeasureSpec.getSize(widthMeasureSpec);

       
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
       
int heightSpecSize =  MeasureSpec.getSize(heightMeasureSpec);

       
if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
           
throw new RuntimeException("SlidingDrawer cannot have UNSPECIFIED dimensions");
       
}

       
final View handle = getHandle();
       
final View content = getContent();
        measureChild
(handle, widthMeasureSpec, heightMeasureSpec);

       
if (mVertical) {
           
int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset;
            content
.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, heightSpecMode));
            heightSpecSize
= handle.getMeasuredHeight() + mTopOffset + content.getMeasuredHeight();
            widthSpecSize
= content.getMeasuredWidth();
           
if (handle.getMeasuredWidth() > widthSpecSize) widthSpecSize = handle.getMeasuredWidth();
       
}
       
else {
           
int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
            getContent
().measure(MeasureSpec.makeMeasureSpec(width, widthSpecMode), heightMeasureSpec);
            widthSpecSize
= handle.getMeasuredWidth() + mTopOffset + content.getMeasuredWidth();
            heightSpecSize
= content.getMeasuredHeight();
           
if (handle.getMeasuredHeight() > heightSpecSize) heightSpecSize = handle.getMeasuredHeight();
       
}

        setMeasuredDimension
(widthSpecSize, heightSpecSize);
   
}

   
private boolean mVertical;
   
private int mTopOffset;
}
</pre>And in xml:
<div>
</div><div><pre class="default prettyprint" style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;"><FrameLayout android:layout_width="fill_parent"
             
android:layout_height="fill_parent">
    ... stuff you want to cover at full-size ...
   

       
<com.package.WrappingSlidingDrawer android:layout_width="fill_parent"
                           
android:layout_height="wrap_content"
                           
android:content="@+id/content"
                           
android:handle="@+id/handle"
</pre><pre class="default prettyprint" style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;"> android:gravity="bottom">
            ... handle and content views ...
       
</com.package.WrappingSlidingDrawer>
   

</FrameLayout>
</pre>Source</div>

Blog Logo

Daniel Gomez Rico


Published

Image

MakinGIANTS

The findings and tips records of an Android-iOS-TheWholeShabang group

Back to Overview