5

I am working with android.I had used slider library in my application.

Now I want to add a button to handle the slide activity,so I can swipe contents along with button to open and close as in the picture.After close the slide menu, button will appear infront of the activity.

I don't know whether it is possible or not.

Please help me if you are familiar with this library, thanks in advance :)

enter image description here

enter image description here

I used the following code to access slider content

       SlidingMenu menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setApp_id("ads");
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setSecondaryMenu(R.layout.slide);
Maxwell
  • 552
  • 2
  • 5
  • 20

2 Answers2

0

Try this link it will help you: Left to Right Sliding Drawer Creation in Android

<?xml version="1.0" encoding="utf-8"?>

        <LinearLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="horizontal"
         android:gravity="center_vertical"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">

         <balaji.slidingdrawer_lr.Transparent
             android:id="@+id/popup_window"
             android:orientation="vertical"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:gravity="left"
             android:padding="30px">

             <TextView
          android:id="@+id/textView1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
          android:textColor="#000000"
              android:textSize="20dp"
              android:paddingTop="20dp"
              android:paddingBottom="20dp"
              android:text="Left to Right Sliding" />

             <CheckBox 
              android:id="@+id/checkBox1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:textSize="17dp"
          android:text="Jelly Bean" />

             <CheckBox 
              android:id="@+id/checkBox2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:textSize="17dp"
          android:text="Ice Cream Sandwich" />

             <CheckBox 
              android:id="@+id/checkBox3"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content" 
          android:textSize="17dp"
          android:text="HoneyComb" />

         </balaji.slidingdrawer_lr.Transparent>

         <Button 
             android:id="@+id/handle"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="Handle"/>

        </LinearLayout>

This is the layout for left to right sliding drawer. You also need the balaji.slidingdrawer_lr.Transparent . Here is the code for it:

package balaji.slidingdrawer_lr;

    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.graphics.RectF;
    import android.graphics.Paint.Style;
    import android.util.AttributeSet;
    import android.widget.LinearLayout;

    public class Transparent extends LinearLayout 
    {
     private Paint innerPaint, borderPaint ;

     public Transparent(Context context, AttributeSet as) {
      super(context, as);
      init();
     }

     public Transparent(Context context) {
      super(context);
      init();
     }

     private void init() {
      innerPaint = new Paint();
      innerPaint.setARGB(225, 75, 75, 255); 
      innerPaint.setAntiAlias(true);
      borderPaint = new Paint();
      borderPaint.setARGB(255, 255, 255, 255);
      borderPaint.setAntiAlias(true);
      borderPaint.setStyle(Style.STROKE);
      borderPaint.setStrokeWidth(20);
     }

     public void setInnerPaint(Paint innerPaint) {
      this.innerPaint = innerPaint;
     }

     public void setBorderPaint(Paint borderPaint) {
      this.borderPaint = borderPaint;
     }

     @Override
     protected void dispatchDraw(Canvas canvas) {
      RectF drawRect = new RectF();
      drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
      canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
      canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
      super.dispatchDraw(canvas);
            }
    }

You need this two files for your needs. Hope this will help you.

W3hri
  • 1,563
  • 2
  • 18
  • 31
Imran Betara
  • 649
  • 3
  • 8
0

If your main concern is adding your image on Layout then you can do some thing like that ..

Step(1) Use RelativeLayout as your parent.

Step(2) For your image view use like this ..

<ImageView
                android:id="@+id/iv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/content_frame"
                android:layout_alignParentTop="@+id/content_frame"
                android:layout_centerInParent="true"
                android:src="@drawable/slider" />

Step(3) Now get id of this image view in your java class and put setOnClickListener to it. Now on click simply put your defined code to close and open. Make sure to put a check on it that is drawer open then close drawer and if drawer closed then open drawer.

Else than this I will suggest you to use ActionBar NavigationDrawer for same .. It is very handy to use.

I have performed same stuff using Navigation Drawer in one of my project .. It is working like charm.

Hope it helps..

EDIT

If you are using ActionBar NavigationDrawer or anything else then your preferred layout should look like this ..

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

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <FrameLayout
                android:id="@+id/content_frame"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true" >

                <fragment
                    android:id="@+id/map"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    class="com.google.android.gms.maps.SupportMapFragment" />

            </FrameLayout>

            <ImageView
                android:id="@+id/iv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/content_frame"
                android:layout_alignParentTop="@+id/content_frame"
                android:layout_centerInParent="true"
                android:src="@drawable/ic_launcher" />



        </RelativeLayout>




        <ListView
            android:id="@+id/listview_drawer_two"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="right"
            android:background="@color/taxi_list_light"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="2dp" />

    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

Just copy and paste this layout in fresh XML file.. and see how it looks like ..

More over this I will suggest you to have a look on this tutorial .. http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

Hope it helps!

AndroidHacker
  • 3,596
  • 1
  • 25
  • 45
  • I used navigation drawer.But How can I places navigation button in my custom position. any idea?? – Maxwell May 01 '14 at 05:39
  • As I mentioned you need to use RelativeLayout and put your IV as I mentioned .. Kindly put your layout part .. – AndroidHacker May 01 '14 at 07:20
  • check the library I used(above link) and ,tell me if u have any idea about ...because I need to call this from a library project.. – Maxwell May 01 '14 at 07:24
  • I mean I used slide content from behind using the library..But I need a button infront of the screen as the part of the behind view an I can slide button to view the slide content.Its should call from library so.. I need to code of button as a content from the library – Maxwell May 01 '14 at 07:37