Ribbon Menu

I read somewhere that Google called this the “feed menu”.

Anyway, this is what I mean (look at this blog ):

Ribbon menu

This is a Google+ app. If you click the G + icon on the action bar, the whole screen will move to the right and a menu will appear. Note that the ActionBar is also moving.

I want to do this in my application, but I do not know how. I have a basic understanding of the basics of animation.

Questions:

  • What type of layout do I need to use?
  • How to animate the whole screen (using the action bar)?

I hope these are not too general questions. I ask for examples. Thanks in advance.

+6
source share
4 answers

OK I understood. It's simple.

getWindow().getDecorView(); 

This line gives you the main activity. The main view contains everything that is displayed in action. Then you can animate it. The answer was simple.

This link helped me a lot: http://android.cyrilmottier.com/?p=658

EDIT:

This is not the way. As Cyril Mottier said it was a hack, and I found a lot of problems. I redid everything and now I am implementing my own ActionBar.

+2
source

You can do it with the navigation box very well. Here is an example I found

MainActivity.java

 package ir.ZiaNazari.navigationdrawer; import android.os.Bundle; import android.app.Activity; import android.content.res.Configuration; import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private String[] drawerListViewItems; private DrawerLayout drawerLayout; private ListView drawerListView; private ActionBarDrawerToggle actionBarDrawerToggle; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // get list items from strings.xml drawerListViewItems = getResources().getStringArray(R.array.items); // get ListView defined in activity_main.xml drawerListView = (ListView) findViewById(R.id.left_drawer); // Set the adapter for the list view drawerListView.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_listview_item, drawerListViewItems)); // 2. App Icon drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // 2.1 create ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle( this, /* host Activity */ drawerLayout, /* DrawerLayout object */ R.drawable.ic_launcher, /* nav drawer icon to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ); // 2.2 Set actionBarDrawerToggle as the DrawerListener drawerLayout.setDrawerListener(actionBarDrawerToggle); // 2.3 enable and show "up" arrow getActionBar().setDisplayHomeAsUpEnabled(true); // just styling option drawerLayout.setDrawerShadow(R.drawable.ic_launcher, GravityCompat.START); drawerListView.setOnItemClickListener(new DrawerItemClickListener()); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. actionBarDrawerToggle.syncState(); } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); actionBarDrawerToggle.onConfigurationChanged(newConfig); } @Override public boolean onOptionsItemSelected(MenuItem item) { // call ActionBarDrawerToggle.onOptionsItemSelected(), if it returns true // then it has handled the app icon touch event if (actionBarDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); } private class DrawerItemClickListener implements ListView.OnItemClickListener { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Toast.makeText(MainActivity.this, ((TextView)view).getText(), Toast.LENGTH_LONG).show(); drawerLayout.closeDrawer(drawerListView); } } } 

drawer_listview_item.xml

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/text1" android:textColor="#fff" android:textSize="20sp" android:gravity="center_vertical" android:paddingStart="14.5sp" android:paddingEnd="14.5sp" android:minHeight="35sp" > </TextView> 

activity_main.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="@drawable/myshape" > <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- The navigation drawer --> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="#666" android:dividerHeight="1dp" android:background="#333" android:paddingLeft="15sp" android:paddingRight="15sp" /> </android.support.v4.widget.DrawerLayout> 

string.xml

 <?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">Navigation Drawer</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string-array name="items"> <item>Item 1</item> <item>Item 2</item> <item>Item 3</item> <item>Item 4</item> <item>Item 5</item> <item>Item 6</item> </string-array> <string name="drawer_open">Open navigation drawer</string> <string name="drawer_close">Close navigation drawer</string> </resources> 

Hope this helps you and other people.

0
source

Source: https://habr.com/ru/post/920211/


All Articles