功能区菜单Android

时间:2012-07-11 10:52:52

标签: android animation menu

我在某处读到谷歌称之为“功能区菜单”。

无论如何这就是我的意思(也看看这个blog):

Ribbon menu http://img151.imageshack.us/img151/9931/48156844.jpg

这是Google+应用。当您单击ActionBar上的G +图标时,整个屏幕向右移动并出现一个菜单。请注意,ActionBar也会移动。

我想在我的应用程序中执行此操作,但我不知道如何操作。我对动画框架有基本的了解。

问题是:

  • 我必须使用哪种布局?
  • 如何为整个屏幕设置动画(使用ActionBar)?

我希望这些不是太普通的问题。我在问一些例子。提前谢谢。

4 个答案:

答案 0 :(得分:2)

好的,我明白了。这很简单。

getWindow().getDecorView();

此行为您提供活动的主视图。主视图包含活动中显示的所有内容。然后你可以动画它。答案很简单。

此链接对我有很大帮助:http://android.cyrilmottier.com/?p=658

编辑:

这不是继续进行的方式。就像Cyril Mottier说这是一个黑客,我发现了很多问题。 我重新编写了一切,现在我正在实现自己的ActionBar。

答案 1 :(得分:2)

答案 2 :(得分:0)

你可以通过导航抽屉做到这一点, 这是我找到的样本

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>

我希望这可以帮助你和其他人

答案 3 :(得分:0)