6

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

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

功能区菜单

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

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

问题是:

  • 我必须使用什么样的布局?
  • 如何为整个屏幕设置动画(使用 ActionBar)?

我希望这些不是太笼统的问题。我在问例子。先感谢您。

4

3 回答 3

3

好,我知道了。这很简单。

getWindow().getDecorView();

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

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

编辑:

这不是继续的方法。就像 Cyril Mottier 所说的那样,这是一个 hack,我发现了很多问题。我重做了一切,现在我正在实现自己的 ActionBar。

于 2012-07-16T11:35:21.490 回答
1

我也在寻找这个。同一事物的另一个名称是滑出导航。以下是我在 Github 上找到的解决方案:

https://github.com/jfeinstein10/SlidingMenu

https://github.com/korovyansk/android-fb-like-slideout-navigation

https://github.com/darvds/RibbonMenu

https://github.com/Gregadeaux/android-fly-in-app-navigation

于 2012-07-27T20:57:51.820 回答
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);

    }
}
}

抽屉列表视图项目.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>

字符串.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>

我希望这对您和其他人有所帮助

于 2013-11-06T05:43:21.833 回答