‘壹’ android studio 侧滑删除,下拉刷新怎么做
1、SwipeMenuListView继承ListView。
public class SwipeMenuListView extends ListView {11
2、重写setAdapter方法,然后创建一个SwipeMenuLayout包含我们自己adapter中getView返回的View跟我们的侧滑菜单。
@Override
public void setAdapter(ListAdapter adapter) {
super.setAdapter(new SwipeMenuAdapter(getContext(), adapter) {
@Override
public void createMenu(SwipeMenu menu) {
if (mMenuCreator != null) {
mMenuCreator.create(menu);
Log.e("TAG", "---createMenu--");
}
‘贰’ android 怎样让drawerlayout设置的侧滑菜单的内容充满屏幕
现在侧滑菜单使用很多,大都是通过SlidingMenu实现。现在也可以通过DrawerLayout
创建抽屉布局
frament_content.xml
[html] view plain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/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 plain
<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" >
<!-- 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 plain
/**
* 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 plain
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 ArrayList<String> menuLists;
private ArrayAdapter<String> 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 ArrayList<String>();
for (int i = 0; i < 5; i++)
menuLists.add("菜单0" + i);
adapter = new ArrayAdapter<String>(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("http://www..com");
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 滑动菜单(slide menu) 背景 亮度和透明度设置
首先在sdk目录下source源码目录下搜索DrawerLayout文件,把相关的java文件导入工程
以5.0为例
@Override
protectedbooleandrawChild(Canvascanvas,Viewchild,longdrawingTime){
finalintheight=getHeight();
finalbooleandrawingContent=isContentView(child);
intclipLeft=0,clipRight=getWidth();
finalintrestoreCount=canvas.save();
if(drawingContent){
finalintchildCount=getChildCount();
for(inti=0;i<childCount;i++){
finalViewv=getChildAt(i);
if(v==child||v.getVisibility()!=VISIBLE||
!hasOpaqueBackground(v)||!isDrawerView(v)||
v.getHeight()<height){
continue;
}
if((v,Gravity.LEFT)){
finalintvright=v.getRight();
if(vright>clipLeft)clipLeft=vright;
}else{
finalintvleft=v.getLeft();
if(vleft<clipRight)clipRight=vleft;
}
}
canvas.clipRect(clipLeft,0,clipRight,getHeight());
}
finalbooleanresult=super.drawChild(canvas,child,drawingTime);
canvas.restoreToCount(restoreCount);
if(mScrimOpacity>0&&drawingContent){
/*
*这里是直接用画笔画了一层有透明度的方块覆盖在主内容上方,产生慢*慢变暗的效果,所以我们只需要在这里修改即可,
*根据代码逻辑可以知道我们只需要改变imag即可
*/
finalintbaseAlpha=(mScrimColor&0xff000000)>>>24;
finalintimag=(int)(baseAlpha*mScrimOpacity);
finalintcolor=imag<<24|(mScrimColor&0xffffff);
mScrimPaint.setColor(color);
canvas.drawRect(clipLeft,0,clipRight,getHeight(),mScrimPaint);
}elseif(mShadowLeft!=null&&(child,Gravity.LEFT)){
finalintshadowWidth=mShadowLeft.getIntrinsicWidth();
finalintchildRight=child.getRight();
finalintdrawerPeekDistance=mLeftDragger.getEdgeSize();
finalfloatalpha=
Math.max(0,Math.min((float)childRight/drawerPeekDistance,1.f));
//这里是绘制菜单的覆盖物
mShadowLeft.setBounds(childRight,child.getTop(),
childRight+shadowWidth,child.getBottom());
mShadowLeft.setAlpha((int)(0xff*alpha));
mShadowLeft.draw(canvas);
}elseif(mShadowRight!=null&&(child,Gravity.RIGHT)){
finalintshadowWidth=mShadowRight.getIntrinsicWidth();
finalintchildLeft=child.getLeft();
finalintshowing=getWidth()-childLeft;
finalintdrawerPeekDistance=mRightDragger.getEdgeSize();
finalfloatalpha=
Math.max(0,Math.min((float)showing/drawerPeekDistance,1.f));
mShadowRight.setBounds(childLeft-shadowWidth,child.getTop(),
childLeft,child.getBottom());
mShadowRight.setAlpha((int)(0xff*alpha));
mShadowRight.draw(canvas);
}
returnresult;
}
改变代码之后保存
这时候在布局文件中就不要使用android-supportv4包下的DrawerLayout的,改成你工程里修改后的DrawerLayout,运行就达到效果了
‘肆’ android webView 加载H5页面如何实现左右侧滑效果返回上一页
不是原生Activity没关系 只要继承Activity就没问题,监听滑动事件就行了
‘伍’ android 怎么侧滑一个activity
看了一下这个效果,最先想到的办法是利用一个叫“SlidMenu”的开源控件库(就是人人/FaceBook/Path 样式的侧边菜单),通过设置参数可以是侧边菜单显示全屏。网络很多资源下载的、
还有一种思路是自定义控件,FrameLayout实现两层,上面层监听滑动事件,下面层显示列表,但是这个办法有一个难点就是随手指移动上层逐渐变小的功能,对于新手来说可能困难
‘陆’ android studio侧滑drawerlayout怎么加入几个button在侧滑栏里
很简单,你的双脚没有保持平行一直线上。 或者你侧滑之前有旋转动作!
‘柒’ android 侧滑菜单 有谁知道京东商城分类中的侧滑效果是怎样实现的呢希望可以分享一下代码。
这个我给你个代码 你看看主要通过FrameLayout实现的!!
‘捌’ android怎么实现类似qq那样的右滑出现侧拉菜单
Android 实现类似QQ侧滑菜单,实现左右侧滑 源码。具有iOS 7/8 parallax effect 风格的侧边菜单,类似于最新版qq的菜单效果。ReisdeMenu 创意灵感来自于Dribbble1还有2,而这个是Android版的ResideMenu,在视觉效果上部分参考了iOS版的RESideMenu
‘玖’ android中我使用了drawerlayout实现侧滑菜单,主界面是一个listview,为什么
给侧滑菜单布局添加属性android:clickable="true"