Andriod学习教程之滑动布局(14)

本文实例为大家分享了Andriod滑动布局的具体代码,供大家参考,具体内容如下

MainActivity.java代码:

package siso.swipelayoutdemo;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.nineoldandroids.view.ViewHelper;

import siso.swipelib.SwipeLayout;

public class MainActivity extends AppCompatActivity {

 private SwipeLayout sample1, sample2, sample3;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  sample1 = (SwipeLayout) findViewById(R.id.sample1);
  sample1.setShowMode(SwipeLayout.ShowMode.PullOut);
  View starBottView = sample1.findViewById(R.id.starbott);
  sample1.addDrag(SwipeLayout.DragEdge.Left, sample1.findViewById(R.id.bottom_wrapper));
  sample1.addDrag(SwipeLayout.DragEdge.Right, sample1.findViewById(R.id.bottom_wrapper_2));
  sample1.addDrag(SwipeLayout.DragEdge.Top, starBottView);
  sample1.addDrag(SwipeLayout.DragEdge.Bottom, starBottView);
  sample1.addRevealListener(R.id.delete, new SwipeLayout.OnRevealListener() {
   @Override
   public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {

   }
  });

  sample1.getSurfaceView().setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Click on surface", Toast.LENGTH_SHORT).show();
    Log.d(MainActivity.class.getName(), "click on surface");
   }
  });
  sample1.getSurfaceView().setOnLongClickListener(new View.OnLongClickListener() {
   @Override
   public boolean onLongClick(View v) {
    Toast.makeText(MainActivity.this, "longClick on surface", Toast.LENGTH_SHORT).show();
    Log.d(MainActivity.class.getName(), "longClick on surface");
    return true;
   }
  });
  sample1.findViewById(R.id.star2).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Star", Toast.LENGTH_SHORT).show();
   }
  });

  sample1.findViewById(R.id.trash2).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Trash Bin", Toast.LENGTH_SHORT).show();
   }
  });

  sample1.findViewById(R.id.magnifier2).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Magnifier", Toast.LENGTH_SHORT).show();
   }
  });

  sample1.addRevealListener(R.id.starbott, new SwipeLayout.OnRevealListener() {
   @Override
   public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {
    View star = child.findViewById(R.id.star);
    float d = child.getHeight() / 2 - star.getHeight() / 2;
    ViewHelper.setTranslationY(star, d * fraction);
    ViewHelper.setScaleX(star, fraction + 0.6f);
    ViewHelper.setScaleY(star, fraction + 0.6f);
   }
  });

  //sample2

  sample2 = (SwipeLayout) findViewById(R.id.sample2);
  sample2.setShowMode(SwipeLayout.ShowMode.LayDown);
  sample2.addDrag(SwipeLayout.DragEdge.Right, sample2.findViewWithTag("Bottom2"));
 sample2.findViewById(R.id.star).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Star", Toast.LENGTH_SHORT).show();
   }
  });

  sample2.findViewById(R.id.trash).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Trash Bin", Toast.LENGTH_SHORT).show();
   }
  });

  sample2.findViewById(R.id.magnifier).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Magnifier", Toast.LENGTH_SHORT).show();
   }
  });

  sample2.findViewById(R.id.click).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Yo", Toast.LENGTH_SHORT).show();
   }
  });
  sample2.getSurfaceView().setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Click on surface", Toast.LENGTH_SHORT).show();
   }
  });

  //sample3

  sample3 = (SwipeLayout) findViewById(R.id.sample3);
  sample3.addDrag(SwipeLayout.DragEdge.Top, sample3.findViewWithTag("Bottom3"));
  sample3.addRevealListener(R.id.bottom_wrapper_child1, new SwipeLayout.OnRevealListener() {
   @Override
   public void onReveal(View child, SwipeLayout.DragEdge edge, float fraction, int distance) {
    View star = child.findViewById(R.id.star);
    float d = child.getHeight() / 2 - star.getHeight() / 2;
    ViewHelper.setTranslationY(star, d * fraction);
    ViewHelper.setScaleX(star, fraction + 0.6f);
    ViewHelper.setScaleY(star, fraction + 0.6f);
    int c = (Integer) evaluate(fraction, Color.parseColor("#dddddd"), Color.parseColor("#4C535B"));
    child.setBackgroundColor(c);
   }
  });
  sample3.findViewById(R.id.bottom_wrapper_child1).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Yo!", Toast.LENGTH_SHORT).show();
   }
  });
  sample3.getSurfaceView().setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(MainActivity.this, "Click on surface", Toast.LENGTH_SHORT).show();
   }
  });

 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {

  getMenuInflater().inflate(R.menu.my, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {

  int id = item.getItemId();
  if (id == R.id.action_listview) {
   startActivity(new Intent(this, ListViewExample.class));
   return true;
  } else if (id == R.id.action_gridview) {
   startActivity(new Intent(this, GridViewExample.class));
   return true;
  } else if (id == R.id.action_nested) {
   startActivity(new Intent(this, NestedExample.class));
   return true;
  } else if (id == R.id.action_recycler) {
   startActivity(new Intent(this, RecyclerViewExample.class));
  }
  return super.onOptionsItemSelected(item);
 }

 /*
 Color transition method.
  */
 public Object evaluate(float fraction, Object startValue, Object endValue) {
  int startInt = (Integer) startValue;
  int startA = (startInt >> 24) & 0xff;
  int startR = (startInt >> 16) & 0xff;
  int startG = (startInt >> 8) & 0xff;
  int startB = startInt & 0xff;

  int endInt = (Integer) endValue;
  int endA = (endInt >> 24) & 0xff;
  int endR = (endInt >> 16) & 0xff;
  int endG = (endInt >> 8) & 0xff;
  int endB = endInt & 0xff;

  return (int) ((startA + (int) (fraction * (endA - startA))) << 24) |
    (int) ((startR + (int) (fraction * (endR - startR))) << 16) |
    (int) ((startG + (int) (fraction * (endG - startG))) << 8) |
    (int) ((startB + (int) (fraction * (endB - startB))));
 }
}

NestedExample.java代码:

package siso.swipelayoutdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import siso.swipelib.SwipeLayout;

public class NestedExample extends Activity{

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.complicate_layout);
   SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.test_swipe_swipe);
  swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
   @Override
   public void onDoubleClick(SwipeLayout layout, boolean surface) {
    Toast.makeText(getApplicationContext(), "DoubleClick", Toast.LENGTH_SHORT).show();
   }
  });
  swipeLayout.findViewById(R.id.trash).setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    Toast.makeText(getApplicationContext(), "Click", Toast.LENGTH_SHORT).show();
   }
  });
 }
}

RecyclerViewExample.java代码:

package siso.swipelayoutdemo;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import java.util.ArrayList;
import java.util.Arrays;

import jp.wasabeef.recyclerview.animators.FadeInLeftAnimator;
import siso.swipelayoutdemo.adapter.RecyclerViewAdapter;
import siso.swipelayoutdemo.adapter.util.DividerItemDecoration;
import siso.swipelib.util.Attributes;

public class RecyclerViewExample extends Activity {

 private RecyclerView recyclerView;
 private RecyclerView.Adapter mAdapter;

 private ArrayList<String> mDataSet;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.recyclerview);
  recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
   ActionBar actionBar = getActionBar();
   if (actionBar != null) {
    actionBar.setTitle("RecyclerView");
   }
  }

  // Layout Managers:
  recyclerView.setLayoutManager(new LinearLayoutManager(this));

  // Item Decorator:
  recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.divider)));
  recyclerView.setItemAnimator(new FadeInLeftAnimator());

  // Adapter:
  String[] adapterData = new String[]{"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};
  mDataSet = new ArrayList<String>(Arrays.asList(adapterData));
  mAdapter = new RecyclerViewAdapter(this, mDataSet);
  ((RecyclerViewAdapter) mAdapter).setMode(Attributes.Mode.Single);
  recyclerView.setAdapter(mAdapter);

  /* Listeners */
  recyclerView.setOnScrollListener(onScrollListener);
 }

 RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
  @Override
  public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
   super.onScrollStateChanged(recyclerView, newState);
   Log.e("ListView", "onScrollStateChanged");
  }

  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
   super.onScrolled(recyclerView, dx, dy);

  }
 };

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {

  getMenuInflater().inflate(R.menu.my, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {

  int id = item.getItemId();
  if (id == R.id.action_listview) {
   startActivity(new Intent(this, ListViewExample.class));
   finish();
   return true;
  } else if (id == R.id.action_gridview) {
   startActivity(new Intent(this, GridViewExample.class));
   finish();
   return true;
  }
  return super.onOptionsItemSelected(item);
 }
}

ListViewExample.java代码:

package siso.swipelayoutdemo;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import siso.swipelayoutdemo.adapter.ListViewAdapter;
import siso.swipelib.SwipeLayout;
import siso.swipelib.util.Attributes;

public class ListViewExample extends Activity {

 private ListView mListView;
 private ListViewAdapter mAdapter;
 private Context mContext = this;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.listview);
  mListView = (ListView) findViewById(R.id.listview);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
   ActionBar actionBar = getActionBar();
   if (actionBar != null) {
    actionBar.setTitle("ListView");
   }
  }

  mAdapter = new ListViewAdapter(this);
  mListView.setAdapter(mAdapter);
  mAdapter.setMode(Attributes.Mode.Single);
  mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ((SwipeLayout)(mListView.getChildAt(position - mListView.getFirstVisiblePosition()))).open(true);
   }
  });
  mListView.setOnTouchListener(new View.OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
    Log.e("ListView", "OnTouch");
    return false;
   }
  });
  mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
   @Override
   public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    Toast.makeText(mContext, "OnItemLongClickListener", Toast.LENGTH_SHORT).show();
    return true;
   }
  });
  mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
   @Override
   public void onScrollStateChanged(AbsListView view, int scrollState) {
    Log.e("ListView", "onScrollStateChanged");
   }

   @Override
   public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

   }
  });

  mListView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
   @Override
   public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    Log.e("ListView", "onItemSelected:" + position);
   }

   @Override
   public void onNothingSelected(AdapterView<?> parent) {
    Log.e("ListView", "onNothingSelected:");
   }
  });

 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {

  getMenuInflater().inflate(R.menu.my, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {

  int id = item.getItemId();
  if (id == R.id.action_listview) {
   startActivity(new Intent(this, ListViewExample.class));
   finish();
   return true;
  } else if (id == R.id.action_gridview) {
   startActivity(new Intent(this, GridViewExample.class));
   finish();
   return true;
  } else if (id == R.id.action_recycler) {
   startActivity(new Intent(this, RecyclerViewExample.class));
   finish();
   return true;
  }
  return super.onOptionsItemSelected(item);
 }
}

GridViewExample.java代码:

package siso.swipelayoutdemo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import siso.swipelayoutdemo.adapter.GridViewAdapter;
import siso.swipelib.util.Attributes;

public class GridViewExample extends Activity{

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.gridview);
  final GridView gridView = (GridView)findViewById(R.id.gridview);
  final GridViewAdapter adapter = new GridViewAdapter(this);
  adapter.setMode(Attributes.Mode.Multiple);
  gridView.setAdapter(adapter);
  gridView.setSelected(false);
  gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
   @Override
   public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    Log.e("onItemLongClick","onItemLongClick:" + position);
    return false;
   }
  });
  gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Log.e("onItemClick","onItemClick:" + position);
   }
  });

  gridView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
   @Override
   public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    Log.e("onItemSelected","onItemSelected:" + position);
   }

   @Override
   public void onNothingSelected(AdapterView<?> parent) {

   }
  });

 }
}

app项目结构:

Andriod类库项目结构:

build.gradle

apply plugin: 'com.android.application'

android {
 compileSdkVersion 23
 buildToolsVersion "23.0.1"

 defaultConfig {
  applicationId "siso.swipelayoutdemo"
  minSdkVersion 22
  targetSdkVersion 22
  versionCode 1
  versionName "1.0"
 }
 buildTypes {
  release {
   minifyEnabled false
   proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  }
 }
}

dependencies {
 compile fileTree(include: ['*.jar'], dir: 'libs')
 testCompile 'junit:junit:4.12'
 compile 'com.android.support:appcompat-v7:23.0.1'
 compile project(path: ':swipelib')
 compile 'com.android.support:recyclerview-v7:23.3.0'
 compile 'com.daimajia.easing:library:1.0.0@aar'
 compile 'com.daimajia.androidanimations:library:1.1.2@aar'
 compile 'com.nineoldandroids:library:2.4.0'
 compile 'jp.wasabeef:recyclerview-animators:1.0.3@aar'
}

运行结果如图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Andriod 自定义控件之音频条

    今天我们实现一个直接继承于View的全新控件.大家都知道音乐播放器吧,在点击一首歌进行播放时,通常会有一块区域用于显示音频条,我们今天就来学习下,播放器音频条的实现. 首先我们还是先定义一个类,直接继承于View,并重写它的构造方法,并初始化一个画笔,这和上一节是同样的道理.直接贴出代码: public class AudioBar extends View{ private Paint mTextPaint; public AudioBar(Context context) { this(co

  • Andriod arcgis保存Mapview为图片的实例代码

    废话不多说了,直接给大家贴代码了,具体代码如下所述: /** * 把一个View的对象转换成bitmap */ private Bitmap getViewBitmap(MapView v) { v.clearFocus(); v.setPressed(false); //能画缓存就返回false boolean willNotCache = v.willNotCacheDrawing(); v.setWillNotCacheDrawing(false); int color = v.getDr

  • Andriod开发中常见问题

    本文为大家总结了Andriod开发中常遇到的问题,供大家学习,具体内容如下 1.Andriod中布局中引用布局的问题 (使用如下方法即可,布局中引用布局可以起到节省资源的问题) <LinearLayout> <include layout="@layout/buttom"> </LinearLayout> 2.如何判断你的手机版本是不是4.0以上 if(Android.os.Build.VERSION.SDK_INT>10) 3.屏幕切换问题和

  • Andriod 获取电池的信息实例代码

    具体代码如下所示: <?xml version="1.0"?> <LinearLayout android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"

  • Java实现Andriod带看括弧的计算器代码

    废话不多说了,一切尽在代码中,具体代码如下所示: 界面 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_par

  • Andriod 读取网络图片实例代码解析

    Android手机上,我们常用ImageView显示图片,我们本章获取网络图片并显示在ImageView中. 一.设计界面 1.布局文件 打开res/layout/activity_main.xml文件. 输入以下代码: <?xml version="." encoding="utf-"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu

  • Andriod 资源文件之存取操作

    废话不多说了,直接给大家贴代码了.具体代码如下所述: <?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="mat

  • Andriod开发中引入jar包的正确方式介绍

    andriod中如果引入jar包的方式不对就会出现一些奇怪的错误. 工作的时候恰好有一个jar包需要调用,结果用了很长时间才解决出现的bug. 刚开始是这样引用的(eclipse): 右键工程,Build path,java build path, 选择libraries,在右边的按钮中点击"Add External JARs", 然后选择合适的jar包(大部分人应该会这样做). 结果控制台立刻报错:conversion to dalvik format failed with err

  • 代码从windows下visual studio到andriod平台迁移实现步骤

    代码从windows下visual studio到andriod平台迁移实现步骤: 前言 前言也是迁言,从windows的visual studio 2012平台迁移到Android平台上,需用修改挺多的代码和需用注意地方. 我们当然的平台当初就考虑了其他平台跨平台的应用问题,所以一开始在windows下就是用cmake来完成工程的建立的,cMakeLists.txt文件都做了一些处理,但是此时只是更针对或说首先保证windows下的编译和使用. 谨此做个记录. 1. modify cMakeL

  • Andriod学习教程之滑动布局(14)

    本文实例为大家分享了Andriod滑动布局的具体代码,供大家参考,具体内容如下 MainActivity.java代码: package siso.swipelayoutdemo; import android.app.Activity; import android.content.Intent; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.B

  • Android学习教程之滑动布局(14)

    本文实例为大家分享了Android滑动布局的具体代码,供大家参考,具体内容如下 MainActivity.java代码: package siso.swipelayoutdemo; import android.app.Activity; import android.content.Intent; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.B

  • 值得分享和收藏的Bootstrap学习教程

    首先先感谢朋友们对小编的支持,关注小编的文章,和小编一起学习进步,一直的陪伴,小编也一定会再接再厉,为大家分享更多精彩的文章. 在分享的过程中遇到了一些问题,这也给了我很大的启发,大家在搜索相关文章时都没有针对此类问题进行的系统整理文章,这也是小编需要在今后进行改进的. 所以本文就吸取这个经验,针对Bootstrap教程进行系统整理,希望对大家的学习有所帮助,便于大家学习. 小编的水平能力都很有限,还望大牛多给一些建议和看法,帮助小编进行改正和提高,如果文中确有不妥之处,还请谅解.希望能和大家共

  • Android开发笔记之Intent初级学习教程

    本文讲述了Android开发笔记之Intent初级学习教程.分享给大家供大家参考,具体如下: 项目创建步骤: New Android Project-> Project name:Intent Build Target:Android 2.2 Application name:IntentDemo Package name:com.b510.intent.activity Create Activity:MainActivity Min SDK Version:8 Finish 1.拨打电话 按

  • 计算机二级python学习教程(3) python语言基本数据类型

    本文继续计算机二级python教程的学习,之前已经学习过了计算机二级python学习教程(1).计算机二级python学习教程(2) 3.1 数字类型 数字类型:整数类型.浮点数类型.复数类型. 整数类型:十进制.二进制.八进制和十六进制. #不同进制的整数之间可以直接运算 >>> 0x3F2/1010 1.0 >>> (0x3F2+1010)/0o1762 2.0 浮点数类型:必须带有小数部分,小数部分可以是0,例如1010.0.表示方法有一般表示(只有十进制)和科学

  • python爬虫框架scrapy代理中间件掌握学习教程

    目录 代理的使用场景 使用 HttpProxyMiddleware 中间件 代理的使用场景 编写爬虫代码的程序员,永远绕不开就是使用代理,在编码过程中,你会碰到如下情形: 网络不好,需要代理: 目标站点国内访问不了,需要代理: 网站封杀了你的 IP,需要代理. 使用 HttpProxyMiddleware 中间件 本次的测试站点依旧使用 http://httpbin.org/,通过访问 http://httpbin.org/ip 可以获取当前请求的 IP 地址. HttpProxyMiddlew

  • Go语言结构体Go range的学习教程

    目录 正文 Go Range 正文 在前一篇博客我们学习了 Go 数组,其要求所有元素为同一数据类型,如果希望存储不同类型的数据,就要用到结构体相关知识. 结构体的定义:存储相同或不同类型的数据集合. 有 C 相关经验,结构体还是比较容易理解的,语法格式如下所示: type struct_variable_type struct { member definition member definition ... member definition } 上述语法格式的关键字是 struct 和 t

  • Java正则表达式学习教程

    本教程旨在帮助你驾驭Java正则表达式,同时也帮助我复习正则表达式. 什么是正则表达式? 正则表达式定义了字符串的模式.正则表达式可以用来搜索.编辑或处理文本.正则表达式并不仅限于某一种语言,但是在每种语言中有细微的差别.Java正则表达式和Perl的是最为相似的. Java正则表达式的类在 java.util.regex 包中,包括三个类:Pattern,Matcher 和 PatternSyntaxException. Pattern对象是正则表达式的已编译版本.他没有任何公共构造器,我们通

  • MyBatis学习教程(六)-调用存储过程

    一.提出需求 查询得到男性或女性的数量, 如果传入的是0就女性否则是男性 二.准备数据库表和存储过程 create table p_user( id int primary key auto_increment, name varchar(), sex char() ); insert into p_user(name,sex) values('A',"男"); insert into p_user(name,sex) values('B',"女"); insert

  • MyBatis学习教程(二)—如何使用MyBatis对users表执行CRUD操作

    上一篇文章MyBatis入门学习教程(一)-MyBatis快速入门中我们讲了如何使用Mybatis查询users表中的数据,算是对MyBatis有一个初步的入门了,今天讲解一下如何使用MyBatis对users表执行CRUD操作.在没奔主题之前,先给大家补充点有关mybatis和crud的基本知识. 什么是 MyBatis? MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架. MyBatis 消除了几乎所有的 JDBC 代码和参数的手工设置以及对结果集的检索.MyBa

随机推荐