189 8069 5689

android侧滑菜单,android侧滑菜单栏中的图片

android 侧滑效果有几种实现方式

虽然现在网上类似这种效果的实现也非常多,可是我发现实现方案大都非常复杂,并不容易理解。但其实这种效果并不难实现,因此我今天给大家带来的也是史上最简单的滑动菜单实现方案。

站在用户的角度思考问题,与客户深入沟通,找到郑州网站设计与郑州网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:做网站、成都做网站、企业官网、英文网站、手机端网站、网站推广、主机域名、虚拟空间、企业邮箱。业务覆盖郑州地区。

首先还是讲一下实现原理。在一个Activity的布局中需要有两部分,一个是菜单(menu)的布局,一个是内容(content)的布局。两个布局横向排列,菜单布局在左,内容布局在右。初始化的时候将菜单布局向左偏移,以至于能够完全隐藏,这样内容布局就会完全显示在Activity中。然后通过监听手指滑动事件,来改变菜单布局的左偏移距离,从而控制菜单布局的显示和隐藏。原理图如下:

将菜单布局的左偏移值改成0时,效果图如下:

android怎么实现类似qq那样的右滑出现侧拉菜单

Android 实现类似QQ侧滑菜单,实现左右侧滑 源码。具有iOS 7/8 parallax effect 风格的侧边菜单,类似于最新版qq的菜单效果。ReisdeMenu 创意灵感来自于Dribbble1还有2,而这个是Android版的ResideMenu,在视觉效果上部分参考了iOS版的RESideMenu

android实现RecyclerView的Item侧滑菜单

1、引入组件

2、布局中添加组件

使用该组件替换普通的RecyclerView即可

3、activity中进行设置

android 怎样让drawerlayout设置的侧滑菜单的内容充满屏幕

现在侧滑菜单使用很多,大都是通过SlidingMenu实现。现在也可以通过DrawerLayout

创建抽屉布局

frament_content.xml

[html] view plaincopy

?xml version="1.0" encoding="utf-8"?

LinearLayout xmlns:android=""

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

TextView

android:id="@+id/textView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textSize="25sp" /

/LinearLayout

activity_main.xml

[html] view plaincopy

android.support.v4.widget.DrawerLayout xmlns:android=""

android:id="@+id/drawer_layout"

android:layout_width="match_parent"

android:layout_height="match_parent"

!-- The main content view --

FrameLayout

android:id="@+id/content_frame"

android:layout_width="match_parent"

android:layout_height="match_parent"

/FrameLayout

!-- The navigation view --

ListView

android:id="@+id/left_drawer"

android:layout_width="240dp"

android:layout_height="match_parent"

android:layout_gravity="start"

android:background="#ffffcc"

android:choiceMode="singleChoice"

android:divider="@android:color/transparent"

android:dividerHeight="0dp"

/ListView

/android.support.v4.widget.DrawerLayout

然后新建一个类继承Fragment类

[java] view plaincopy

/**

* ContentFragment.java

* 版权所有(C) 2015

* 创建者:cuiran 2015-1-3 下午3:25:44

*/

package com.cayden.drawerlayoutdemo;

import android.app.Fragment;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.TextView;

/**

* TODO

* @author cuiran

* @version 1.0.0

*/

public class ContentFragment extends Fragment {

private TextView textView;

@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container,

Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_content, container, false);

textView = (TextView) view.findViewById(R.id.textView);

String text = getArguments().getString("text");

textView.setText(text);

return view;

}

}

完成Activity代码

[java] view plaincopy

package com.cayden.drawerlayoutdemo;

import java.util.ArrayList;

import android.app.Activity;

import android.app.Fragment;

import android.app.FragmentManager;

import android.content.Intent;

import android.content.res.Configuration;

import android.net.Uri;

import android.os.Bundle;

import android.support.v4.app.ActionBarDrawerToggle;

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.AdapterView.OnItemClickListener;

import android.widget.ArrayAdapter;

import android.widget.ListView;

public class MainActivity extends Activity implements OnItemClickListener {

private DrawerLayout mDrawerLayout;

private ListView mDrawerList;

private ArrayListString menuLists;

private ArrayAdapterString adapter;

private ActionBarDrawerToggle mDrawerToggle;

private String mTitle;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mTitle = (String) getTitle();

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

mDrawerList = (ListView) findViewById(R.id.left_drawer);

menuLists = new ArrayListString();

for (int i = 0; i 5; i++)

menuLists.add("菜单0" + i);

adapter = new ArrayAdapterString(this,

android.R.layout.simple_list_item_1, menuLists);

mDrawerList.setAdapter(adapter);

mDrawerList.setOnItemClickListener(this);

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,

R.drawable.ic_drawer, R.string.drawer_open,

R.string.drawer_close) {

@Override

public void onDrawerOpened(View drawerView) {

super.onDrawerOpened(drawerView);

getActionBar().setTitle("请选择");

invalidateOptionsMenu(); // Call onPrepareOptionsMenu()

}

@Override

public void onDrawerClosed(View drawerView) {

super.onDrawerClosed(drawerView);

getActionBar().setTitle(mTitle);

invalidateOptionsMenu();

}

};

mDrawerLayout.setDrawerListener(mDrawerToggle);

//开启ActionBar上APP ICON的功能

getActionBar().setDisplayHomeAsUpEnabled(true);

getActionBar().setHomeButtonEnabled(true);

}

@Override

public boolean onPrepareOptionsMenu(Menu menu) {

boolean isDrawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);

menu.findItem(R.id.action_websearch).setVisible(!isDrawerOpen);

return super.onPrepareOptionsMenu(menu);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

//将ActionBar上的图标与Drawer结合起来

if (mDrawerToggle.onOptionsItemSelected(item)){

return true;

}

switch (item.getItemId()) {

case R.id.action_websearch:

Intent intent = new Intent();

intent.setAction("android.intent.action.VIEW");

Uri uri = Uri.parse("");

intent.setData(uri);

startActivity(intent);

break;

}

return super.onOptionsItemSelected(item);

}

@Override

protected void onPostCreate(Bundle savedInstanceState) {

super.onPostCreate(savedInstanceState);

//需要将ActionDrawerToggle与DrawerLayout的状态同步

//将ActionBarDrawerToggle中的drawer图标,设置为ActionBar中的Home-Button的Icon

mDrawerToggle.syncState();

}

@Override

public void onConfigurationChanged(Configuration newConfig) {

super.onConfigurationChanged(newConfig);

mDrawerToggle.onConfigurationChanged(newConfig);

}

@Override

public void onItemClick(AdapterView? arg0, View arg1, int position,

long arg3) {

// 动态插入一个Fragment到FrameLayout当中

Fragment contentFragment = new ContentFragment();

Bundle args = new Bundle();

args.putString("text", menuLists.get(position));

contentFragment.setArguments(args);

FragmentManager fm = getFragmentManager();

fm.beginTransaction().replace(R.id.content_frame, contentFragment)

.commit();

mDrawerLayout.closeDrawer(mDrawerList);

}

}

什么是android 二级侧滑菜单

像qq一样 点击左上角的图标就出现左边的那个栏目 那个栏目有很多菜单 只要你把点击事件 改成侧滑事件就可以了 滑动调用方法就好了 这个侧滑 建议不要把主菜单用viewpage 会起冲突 谢谢


文章名称:android侧滑菜单,android侧滑菜单栏中的图片
当前链接:http://cdxtjz.cn/article/hociph.html

其他资讯