『壹』 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"