2012-10-16 40 views
2

我已经使用android:rotation =“180”使滑动抽屉水平出现在屏幕左侧。它工作正常。但是,由于旋转,内容看起来倒过来。我也尝试旋转内容布局,但只有在滑动抽屉完全打开后才旋转。请检查我附带的代码。滑动抽屉Android

MainActivity.java

public class MainActivity extends Activity { 

ArrayAdapter<String> myAdapter; 

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

    ListView LV = (ListView) findViewById(R.id.listView1); 

    String [] List = {"item 1","item 2","item 3","item 4"}; 
    myAdapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.textView1, List); 
    LV.setAdapter(myAdapter); 

    } 

activity_main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" > 

<SlidingDrawer 
    android:id="@+id/slidingDrawer1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:content="@+id/listView1" 
    android:handle="@+id/handle" 
    android:orientation="horizontal" 
    android:rotation="180" > 

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

<ListView 
    android:id="@+id/listView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:rotation="180" 
    tools:listitem="@layout/list_item" > 
    </ListView> 

</SlidingDrawer> 

list_item.xml

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

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/ic_launcher" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:padding="10dp" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

</LinearLayout> 
+0

这可能会帮助:http://stackoverflow.com/questions/3793194/android-making-sliding-drawer-to-slide-from-left从右到左 – Magicode

回答

3

我实现了SlidingDrawer组件的完全替代,它从任何毒/工作方向。详情请参阅http://www.github.com/kedzie/DraggableDrawers

现在可以从Maven的中央(maven-android-plugin):

<dependency> 
    <groupid>com.github.kedzie.draggabledrawers</groupId> 
    <artifactId>library</artifactId> 
    <version>1.0.0</version> 
    <type>apklib</type> 
</dependency> 
+0

不错的library.Thanks。我会试试这个来检查当drawerlayouts在另一个之上并且把手在另一个之下时它是否会起作用 – SKK

+1

FOr the记录一个DragLayout可以容纳多个抽屉,但是堆叠应该可以正常工作,因为如果实际拖动抽屉,触摸事件才会被拦截,并且仅供参考,我已经添加了边缘拖动功能..结帐最新的网站http:// kedzie.github.io/DraggableDrawers。 –

+0

@ mark.kedzierski我无法找到您的滑动抽屉代码,它在哪里?链接无效。 –

1

请看看THIS教程。你并不需要旋转抽屉...

+0

我以前见过那个链接。但那不是一个滑动抽屉。它只是隐藏/弹出特定的透明布局。这不能满足滑动效果。 – SKK

+0

您也可以通过传递动画添加滑块效果! –

+0

哦。好的。谢谢。但是,对于初学者来说,这似乎有点麻烦:(我想要做的就是显示一个字符串列表,我会试试看。 – SKK

-2

尝试使用android:gravity="left",而不是旋转

+0

你想让我使用上面的语句吗?对不起,但我觉得它不适用于我 – SKK