2

我使用 android:rotation="180" 使滑动抽屉水平显示在屏幕左侧。它工作正常。但是,由于旋转,内容在其中出现颠倒。我也尝试旋转内容布局,但只有在滑动抽屉完全打开后才会旋转。请检查我随附的代码。

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>
4

3 回答 3

3

I've implemented a complete replacement for the SlidingDrawer component and it works from any side/direction. see http://www.github.com/kedzie/DraggableDrawers for details.

Now available from Maven Central ( maven-android-plugin ):

<dependency>
  <groupid>com.github.kedzie.draggabledrawers</groupId>
  <artifactId>library</artifactId>
  <version>1.0.0</version>
  <type>apklib</type>
</dependency>
于 2013-07-12T00:14:40.837 回答
1

Please take a look at THIS tutorial. You don't need to rotate the drawer...

于 2012-10-16T12:09:26.807 回答
-2

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

于 2012-10-16T12:13:11.490 回答