问题
How to add sliding menu to the activity which are not added in the sliding menu and on activity which extends tab Activity
Any help will be appreciated. Thanks in advance
回答1:
change you main xml to something like this.(before do this,right click on your project->android tools->add support library-do this work twice-)
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000" >
<!-- you main xml,all of your xml -->
</RelativeLayout>
<ScrollView
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" >
<RelativeLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
tools:context=".Tab_login" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignRight="@+id/button3"
android:layout_below="@+id/button3"
android:layout_marginTop="21dp"
android:text="Register" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Log In" />
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_alignRight="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginTop="19dp"
android:text="free User" />
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Button02"
android:layout_alignRight="@+id/Button02"
android:layout_below="@+id/Button02"
android:layout_marginTop="23dp"
android:text="Roaming" />
</RelativeLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
THE RESULT PIC:

回答2:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.mhp.example"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF" >
<!--you main xml,all of your xml-->
</RelativeLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/logoshadow"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="461dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Tab_login"
>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignRight="@+id/button3"
android:layout_below="@+id/button3"
android:layout_marginTop="21dp"
android:background="@drawable/blank_buttons"
android:text="Register" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/blank_buttons"
android:text="Log In"
/>
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_alignRight="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginTop="19dp"
android:background="@drawable/blank_buttons"
android:text="free User" />
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Button02"
android:layout_alignRight="@+id/Button02"
android:layout_below="@+id/Button02"
android:layout_marginTop="23dp"
android:background="@drawable/blank_buttons"
android:text="Roaming" />
</RelativeLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
来源:https://stackoverflow.com/questions/25422883/how-to-add-sliding-menu-to-on-the-activtity-which-extend-tabactivity-in-android