
Android
于大博
如果你不给自己设限,世界上便没有限制你发挥的篱笆。
展开
-
Android中app获取随机颜色方法详细
// get rand colorpublic static String getRandColorCode() { String r,g,b; Random random = new Random(); r = Integer.toHexString(random.nextInt(256)).toUpperCase(); g = Integer.toHexSt...原创 2019-10-31 17:52:35 · 825 阅读 · 0 评论 -
Android项目中dp和px转换关系详解
dpi =分辨率对角线 / 屏幕尺寸px = dp * (dpi / 160)原创 2019-10-23 09:43:29 · 326 阅读 · 0 评论 -
Android接收ByteArray解析
private static final String TAG = "MainActivity";// value为数据源,类型Byte[]byte[] data = (byte[])value.getValue();// Byte[]转换StringLog.d(TAG, "-------------------receive-------data------------------...原创 2019-10-21 16:30:29 · 2349 阅读 · 0 评论 -
Android自定义View控件,实现拖动和位置调换
自定义MediaView控件继承View,实现拖动位置调用功能重写draw方法和touch方法package com.example.media;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.gr...原创 2019-08-23 13:39:25 · 1272 阅读 · 1 评论 -
AndroidStudio项目引入aar包
1.复制aar包到libs路径2.修改build.gradle文件增加一下代码repositories { flatDir { dirs 'libs' }}3.dependencies增加引入原创 2019-08-27 15:43:44 · 914 阅读 · 0 评论 -
Android自定义LinearLayout不执行onDraw方法
设置LinearLayout的背景色可解决不调用问题this.setBackgroundColor(Color.parseColor("#50FFFFFF"));重写下面方法忽略背景色,invalidate();每次都会执行dispatchDraw@Overrideprotected void dispatchDraw(Canvas canvas) { super.dis...原创 2019-08-29 15:41:48 · 1356 阅读 · 1 评论 -
Android自定义LinearLayout引入xml布局,设置资源字体
MusicInfoView.javapackage com.example.media.Component;import android.content.Context;import android.content.res.AssetManager;import android.graphics.Typeface;import android.util.AttributeSet;...原创 2019-08-29 15:48:23 · 1311 阅读 · 0 评论 -
Android的Bitmap.Config中ALPHA_8、ARGB_4444、ARGB_8888和RGB_565
ALPHA_8:Each pixel is stored as a single translucency (alpha) channel. 每个像素信息只存储了alpha这一项信息。ARGB_4444:This field was deprecated in API level 13. Because of the poor quality of this configurat...转载 2019-08-29 17:02:22 · 1094 阅读 · 0 评论 -
Android中invalidate()和postInvalidate() 的区别及使用
Android提供了Invalidate方法实现界面刷新,但是Invalidate不能直接在线程中调用,因为他是违背了单线程模型:Android UI操作并不是线程安全的,并且这些操作必须在UI线程中调用。invalidate()是用来刷新View的,必须是在UI线程中进行工作。比如在修改某个view的显示时,调用invalidate()才能看到重新绘制的界面。invalidate()的调用...转载 2019-08-30 10:16:26 · 621 阅读 · 0 评论 -
Android ViewPager实现3D Gallery效果
使用ViewPager打造的3D画廊,先看效果图:需求点: 1.中间item放大 2.中间item覆盖在两侧item上 3.点击或者滑动两侧的item可以切换ViewPager的当前展示页面所以首先我们想到的肯定是ViewGroup的clipChildren属性,设为false,可以让子view突破ViewGroup的限制...转载 2019-09-25 15:20:44 · 641 阅读 · 0 评论 -
Android线性布局ConstraintLayout必须指定三个位置的相对
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com...原创 2019-08-23 13:29:14 · 1000 阅读 · 0 评论 -
Android定时器使用代码
Timer timer = new Timer();TimerTask task = new TimerTask() { @Override public void run() { // 执行逻辑 }};// 启动定时器,立即开始,1000毫秒触发一次timer.schedule(task,0,1000);// 关闭定时器timer.cance...原创 2019-08-23 13:23:04 · 896 阅读 · 0 评论 -
Android引入外部字体源代码
TextView musicTitleView = (TextView) findViewById(R.id.music_title);TextView musicAuthorView = (TextView) findViewById(R.id.music_author);// font setAssetManager mgr = context.getAssets();Typefa...原创 2019-08-23 13:18:30 · 275 阅读 · 0 评论 -
Windows7系统使用adb remount工具Andorid问题分析
adb remount指令运行出现错误情况分析情况一:adb server version (31) doesn't match this client (36); killing... error:解决方法:结束360手机助手进程情况二: adb remount dm_verity is enabled on the system partition...原创 2019-03-27 15:07:14 · 395 阅读 · 0 评论 -
Android removeCallbacks失效问题详解
实现定时器有很多种方式,在这里我简单的介绍几种方式(1)使用Handler + Runnable的方式Handler handler = new Handler();Runnable runnable = new Runnable() { @Override public void run() { //你要做的事 //........转载 2019-08-19 16:58:45 · 3465 阅读 · 0 评论 -
Android AVD模拟器运行程序install fail
后台显示Session ‘app’: Error Installing APK,运行一个新项目的时候突然出错。原因是虚拟机内存不足!解决办法,单击Tools打开AVD Manager,打开后如下:...原创 2019-08-19 18:25:38 · 473 阅读 · 0 评论 -
Android AIDL使用过程
服务端:1.在Android Studio中 src目录上右键创建一个AIDL文件 并命名,完成后会再main下自动生成一个aidl目录,该目录的包名和java下的包名是一致的。创建完成后样式如下图所示:每次生成的.aidl文件后我们需要build一下才能让系统生成自后我们能使用文件。因为在进程间通信中真正起作用的并不是 AIDL 文件,而是系统据此而生成的文件,在Androi...转载 2019-08-14 22:39:03 · 3380 阅读 · 0 评论 -
android高斯模糊,设置ImageView源图片
public Bitmap gaussianBlurBitmap(Bitmap image, int width, int height) { Log.d("inputimg", Integer.toString(image.getByteCount())); Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width,...原创 2019-08-20 22:00:05 · 917 阅读 · 0 评论 -
Android获取屏幕截图Bitmap去除状态栏
获取控件截图(View或Viewgroup类型都可以获取到),去除状态栏public Bitmap loadBitmapFromViewBySystem() { View view = this.getWindow().getDecorView(); view.buildDrawingCache(); // get status bar ...原创 2019-08-20 22:18:10 · 636 阅读 · 1 评论 -
Android studio 3.3之后版本引入库文件路径变更
recyclerview-v7找不到了,在library里面添加也搜不到了,后来发现了项目中默认引入的Androidx,发现谷歌已经使用Androidx替代了android support library和一些别的widget包,具体列表请查看官网https://developer.android.com/jetpack/androidx/migrateimplementation ...原创 2019-08-12 12:19:12 · 398 阅读 · 0 评论 -
Android打印语句使用
package com.thunder.helloworld; import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.util.EventLogTags;import android.util.Log; public class MainActivity ext...原创 2019-08-22 09:31:09 · 1149 阅读 · 0 评论