android开发:触摸屏触摸事件MotionEvent演示实例

mScaleGesture = new ScaleGestureDetector(this, new ScaleGestureDetector.OnScaleGestureListener() {
@Override
public boolean onScale(ScaleGestureDetector detector) {

mScaleFloat *= detector.getScaleFactor();

String str = “”;

str = “比例:”+detector.getScaleFactor()+” mScaleFloat:”+mScaleFloat+”\n”;

mScaleFloat = Math.max(0.1f,Math.min(mScaleFloat,5.0f));//图像比例,最小0.1,最大5

str += ” mScaleFloat:”+mScaleFloat;
text2.setText(str);

matrix.setScale(mScaleFloat, mScaleFloat);
img.setImageMatrix(matrix);
img.invalidate();

return true;//这里一定要返回真,否则不会继续监听事件
}

android invalid drawable tag vector解决办法

当android报这个错误:

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID

Android invalid drawable tag vector

 

一直都没找到什么好的解决方法,最后是修改appcompat-v7依赖包

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    //compile 'com.android.support:appcompat-v7:24.0.1-beta1'
    //noinspection GradleCompatible
    compile 'com.android.support:appcompat-v7:23.0.1'
}

从24.0.1改成23.0.1问题解决了.

dependencies {
 compile fileTree(include: ['*.jar'], dir: 'libs')
 testCompile 'junit:junit:4.12'
 compile 'com.android.support:appcompat-v7:23.2.1'
 compile 'com.android.support:design:23.2.1'
}

android开发:使用HttpURLConnection读取验证码,并且发送请求进行验证的方法

imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
try {
URL url = new URL(“http://192.168.1.205/verify.php?rand=29569″);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();//建立链接

InputStream in = conn.getInputStream();//读取图片先

bitmap = BitmapFactory.decodeStream(in);//解码图片
handler.sendEmptyMessage(1);//发送消息,把图片显示出去

android开发:传感器操作的实例

text1 = (TextView)findViewById(R.id.text1);//方向传感器
text2 = (TextView)findViewById(R.id.text2);//磁场传感器
text3 = (TextView)findViewById(R.id.text3);//温度传感器
text4 = (TextView)findViewById(R.id.text4);//光感传感器
text5 = (TextView)findViewById(R.id.text5);//压力传感器

mSensor = (SensorManager) getSystemService(SENSOR_SERVICE); //获取Sensor的服务对象

然后在onResume中注册需要开发的传感器监听,代码:
@Override

android开发:为桌面创建一个快捷方式的代码

直接上代码:

Parcelable icon = Intent.ShortcutIconResource.fromContext(mContext,R.mipmap.ic_launcher);//桌面的图标
String appname = getString(R.string.app_name);//快捷方式的名称
Intent intent;

//添加
intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,appname);//名称
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,icon);   //桌面图标
intent.putExtra("duplicate",false);//不允许创建多个快捷方式

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,new Intent(MainActivity.this,MainActivity.class));//设置要启动的class
sendBroadcast(intent);//发送广播
15556575859114
 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |