How to set a handle button in slider content in android?

做~自己de王妃 提交于 2019-11-30 20:59:49

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!

Imran Betara

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.

By setting spannable string in error message or extend EditText and overrite your own error draw mechanism.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!