How to create sliding drawer in both sides opposite to one another?

允我心安 提交于 2019-12-07 11:45:23

问题


I have added the code that working for right to left sliding perfectly but i want sliding from left to right also so check the layout and help me out.Here i have mentioned the layout properly for right to left ,Is it possible to get the Slider window in both sides i mean left and right horizontally...

     <?xml version="1.0" encoding="utf-8"?>
                    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                          android:layout_width="fill_parent"
                            android:layout_height="fill_parent">
              <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                     android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="@drawable/bg"
         android:orientation="vertical" >
       <Button
        android:id="@+id/ship"
        android:layout_width="186dp"
        android:layout_height="23dp"
        android:layout_marginTop="49dp"
        android:background="@drawable/signup"
        android:text="Shipping Calculator"
        android:textColor="#ffffffff"
        android:layout_gravity="center"
        android:textStyle="bold" />

</LinearLayout>
<SlidingDrawer
  android:id="@+id/drawer"
  android:layout_width="match_parent"
     android:layout_height="match_parent"
  android:orientation="horizontal"
  android:handle="@+id/handle"
  android:content="@+id/content">
  <ImageView 
   android:id="@+id/handle"
   android:layout_width="wrap_content"
   android:layout_height="fill_parent" 
   android:src="@drawable/tag"/>

  <LinearLayout
      android:id="@+id/content"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:background="@drawable/slidimage"
      android:orientation="vertical"
      android:padding="10dp" >
 <TextView
            android:id="@+id/text1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="15dp"
            android:layout_marginLeft="51dp"
            android:text="SIGN-UP"
            android:textColor="#000000"
            android:textSize="28dp"
            android:textStyle="bold" />

  </LinearLayout>
 </SlidingDrawer>
 <SlidingDrawer
  android:id="@+id/drawers"
  android:layout_width="match_parent"
     android:layout_height="match_parent"
   android:handle="@+id/handles"
  android:layout_gravity="left"
  android:scrollX="100dp"
  android:orientation="horizontal"
  android:content="@+id/contents">
  <ImageView 
   android:id="@+id/handles"
   android:layout_width="wrap_content"
   android:layout_height="fill_parent" 
    android:layout_gravity="left"
   android:src="@drawable/tag"/>

  <LinearLayout
      android:id="@+id/contents"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
       android:layout_gravity="left"
      android:background="@drawable/slidimage"
      android:orientation="vertical"
      android:padding="10dp" >
 <TextView
            android:id="@+id/text1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="15dp"
            android:layout_marginLeft="51dp"
            android:text="SIGN-UP"
            android:textColor="#000000"
            android:textSize="28dp"
            android:textStyle="bold" />

            </LinearLayout>
 </SlidingDrawer> 

</FrameLayout>

回答1:


I got the answer here statically its not exactly possible to create sliding ,and we cant use android:rotation=180 ,as because it will display error as no resource found, We have to create it programatically.it needs to add view in layout.

In case of single side its simple by using widget only no need any views..But the views are needed when you want to slide in multiple direction.

<SlidingDrawer
  android:id="@+id/drawer"
  android:layout_width="match_parent"
     android:layout_height="match_parent"
  android:orientation="horizontal"
  android:handle="@+id/handle"
  android:content="@+id/content">
  <ImageView 
   android:id="@+id/handle"
   android:layout_width="wrap_content"
   android:layout_height="fill_parent" 
   android:src="@drawable/tag"/>

  <LinearLayout
      android:id="@+id/content"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:background="@drawable/slidimage"
      android:orientation="vertical"
      android:padding="10dp" >
 <TextView
            android:id="@+id/text1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="15dp"
            android:layout_marginLeft="51dp"
            android:text="SIGN-UP"
            android:textColor="#000000"
            android:textSize="28dp"
            android:textStyle="bold" />

  </LinearLayout>
 </SlidingDrawer>

activity.java:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.slider);

}



回答2:


I've created a replacement widget for SlidingDrawer, it works in all directions. See This answer



来源:https://stackoverflow.com/questions/13950908/how-to-create-sliding-drawer-in-both-sides-opposite-to-one-another

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