Android Facebook style slide

前端 未结 25 1975
粉色の甜心
粉色の甜心 2020-11-22 03:23

The new Facebook application and its navigation is so cool. I was just trying to see how it can be emulated in my application.

Anyone has a clue how it can be achie

相关标签:
25条回答
  • 2020-11-22 03:43

    Here is another lib and seems to be the best in my opinion. I did not write it..

    UPDATE:

    This code seems to work best for me and it moves the entire Actionbar similar to the G+ app.

    How did Google manage to do this? Slide ActionBar in Android application

    0 讨论(0)
  • 2020-11-22 03:43

    Can't comment on the answer given by @Paul Grime yet, anyway I've submitted on his github project the fix for the flicker problem....

    I'll post the fix here, maybe someone needs it. You just need to add two lines of code. The first one below the anim.setAnimationListener call:

    anim.setFillAfter(true);
    

    And the second one after app.layout() call:

    app.clearAnimation();
    

    Hope this helps :)

    0 讨论(0)
  • 2020-11-22 03:43

    I found a simplest way for it and its working. Use simple Navigation drawer and call drawer.setdrawerListner() and use mainView.setX() method in on drawerSlide method below or copy my code.

    xml file

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

       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) {
    
            }
        });
     }
    }
    

    Thank You

    0 讨论(0)
  • 2020-11-22 03:43

    Android added the navigation drawer. Refer this

    link

    0 讨论(0)
  • 2020-11-22 03:45

    I've implemented facebook-like slideout navigation in this library project.

    You can easy built it into your application, your UI and navigation. You will need to implement only one Activity and one Fragment, let library know about it - and library will provide all wanted animations and navigation.

    Inside the repo you can find demo-project, with how to use the lib to implement facebook-like navigation. Here is short video with record of demo project.

    Also this lib should be compatible this ActionBar pattern, because is based on Activities transactions and TranslateAnimations (not Fragments transactions and custom Views).

    Right now, the most problem is to make it work well for application, which support both portrait and landscape mode. If you have any feedback, please provide it via github.

    All the best,
    Alex

    0 讨论(0)
  • 2020-11-22 03:46

    For info, as the compatibility library starts with 1.6 and this facebook app is also running on devices with Android 1.5, it could not be done with Fragments.

    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.

    That's a way to do it, and I hope I've been clear enough.

    0 讨论(0)
提交回复
热议问题