新的Facebook应用程序和它的导航太酷了。我只是想看看如何在我的应用程序中模仿它。
有人知道怎么实现吗?
点击左上角按钮,页面滑动,显示如下画面:
YouTube视频
新的Facebook应用程序和它的导航太酷了。我只是想看看如何在我的应用程序中模仿它。
有人知道怎么实现吗?
点击左上角按钮,页面滑动,显示如下画面:
YouTube视频
当前回答
对于信息,因为兼容性库开始1.6和这个facebook应用程序也运行在设备与Android 1.5,它不能用碎片。
The way you could do it, is : Create a "base" activity BaseMenuActivity where you put all the logic for the onItemClickListener for your menu list and defines the 2 animation ("open" and "close"). At the end/beginning of the animations, you show/hide the layout of the BaseMenuActivity (lets call it menu_layout). The layout for this activity is simple, its only a list with items + a transparent part at the right of your list. This part will be clickable and its width will be the same width as your "move button". With that, you'll be able to click on this layout to start the animation to let the content_layout slide to the left and take the whole screen. For each option (i.e. item of the menu list), you create a "ContentActivity" which extends the BaseMenuActivity. Then when you click on an item of the list, you start your ItemSelectedContentActivity with the menu visible (which you'll close as soon as your activity starts). The layouts for each ContentActivity are FrameLayout and includes the and . You just need to move the content_layout and make the menu_layout visible when you want.
这是一种方法,我希望我讲得够清楚了。
其他回答
作为我的Android公共库(ACL)的一部分,我实现了自己的侧边栏。 主要优点:
侧栏可以设置为任何位置:左,上,下,右 主视图和滑动视图都是可点击的 侧栏可以部分显示 侧边栏的可样式属性更容易更改它的样式 maven回购中的神器 一个大图书馆的一部分
源代码:https://github.com/serso/android-common/tree/master/views/src/main/java/org/solovyev/android/view/sidebar
用法:https://github.com/serso/android-common/blob/master/samples/res/layout/acl_view_layout.xml
对于信息,因为兼容性库开始1.6和这个facebook应用程序也运行在设备与Android 1.5,它不能用碎片。
The way you could do it, is : Create a "base" activity BaseMenuActivity where you put all the logic for the onItemClickListener for your menu list and defines the 2 animation ("open" and "close"). At the end/beginning of the animations, you show/hide the layout of the BaseMenuActivity (lets call it menu_layout). The layout for this activity is simple, its only a list with items + a transparent part at the right of your list. This part will be clickable and its width will be the same width as your "move button". With that, you'll be able to click on this layout to start the animation to let the content_layout slide to the left and take the whole screen. For each option (i.e. item of the menu list), you create a "ContentActivity" which extends the BaseMenuActivity. Then when you click on an item of the list, you start your ItemSelectedContentActivity with the menu visible (which you'll close as soon as your activity starts). The layouts for each ContentActivity are FrameLayout and includes the and . You just need to move the content_layout and make the menu_layout visible when you want.
这是一种方法,我希望我讲得够清楚了。
这里是另一个(非常好的)开源库!
它的优点是很容易与ActionBarSherlock集成。
这是github项目链接
这里是谷歌播放下载链接
最近我在开发我的滑动菜单实现版本。它使用流行的J.Feinstein Android库SlidingMenu。
请在GitHub上查看源代码:
https://github.com/baruckis/Android-SlidingMenuImplementation
直接下载app到设备上尝试:
https://play.google.com/store/apps/details?id=com.baruckis.SlidingMenuImplementation
由于注释,代码应该是自解释的。希望对大家有所帮助!;)
我找到了一个最简单的方法。使用简单的导航抽屉并调用drawer. setdrawerlistner(),并在下面的drawerSlide方法中使用mainView.setX()方法或复制我的代码。
xml文件
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" >
<RelativeLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/menu"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:src="@drawable/black_line"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/left_drawer"
android:layout_width="200dp"
android:background="#181D21"
android:layout_height="match_parent"
android:layout_gravity="start"
>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
java文件
public class MainActivity extends AppCompatActivity {
DrawerLayout drawerLayout;
RelativeLayout mainView;
ImageView menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
menu=(ImageView)findViewById(R.id.menu);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mainView=(RelativeLayout)findViewById(R.id.content_frame);
menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawerLayout.openDrawer(Gravity.LEFT);
}
});
drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
mainView.setX(slideOffset * 300);
}
@Override
public void onDrawerOpened(View drawerView) {
}
@Override
public void onDrawerClosed(View drawerView) {
}
@Override
public void onDrawerStateChanged(int newState) {
}
});
}
}
谢谢你!