小编rex*_*rex的帖子

如何使GridLayout适合屏幕大小

GridLayoutAPI文档是非常难学......
有谁可以教我如何设置儿童的任何一个Views到有类似的"权重" LinearLayout

现在看起来所有的都放在左侧,
我已经尝试了很多次,但仍然不能像屏幕的半宽一样.

编辑:我不知道什么时候我可以为孩子做什么wrap_content......即使我想设置一些特定大小的图像,这个班有助于我做ImageView wrap_content.........它不能正常运行,我错过了一些设置吗?!?

android widget

34
推荐指数
3
解决办法
11万
查看次数

"new A()"和"A.newInstance()"之间有什么区别?

我什么时候应该更喜欢一个?下面显示的方法的目的是什么?

class A {
    public static A newInstance() {
        A a = new A();
        return a ;
    }
}
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释这两个电话之间的区别吗?

java singleton android design-patterns android-fragments

13
推荐指数
1
解决办法
8402
查看次数

这是一种停止处理的完美方式吗?

我总是创建两个处理程序:一个是在主线程上进行包装,另一个是在单个线程上进行包装.

这是在Activity生命周期中启动和停止这些的最佳方法吗?

HandlerThread safeThread = null;
Handler safeHandler = null;
Handler handler = null;


@Override
    public void onStart() {

if (safeThread == null) {
            safeThread = new HandlerThread("safeThread");
            safeThread.start();
            safeHandler = new Handler(safeThread.getLooper());
        } else if (safeThread.getState() == Thread.State.NEW) {
            safeThread.start();
            safeHandler = new Handler(safeThread.getLooper());
        } else if (safeThread.getState() == Thread.State.WAITING) {
            safeHandler = new Handler(safeThread.getLooper());
        } else if (safeThread.getState() == Thread.State.TERMINATED) {
            safeThread = null;
            safeThread = new HandlerThread("safeThread");
            safeThread.start();
            safeHandler = new Handler(safeThread.getLooper());
        }
}




protected void onStop() …
Run Code Online (Sandbox Code Playgroud)

multithreading android

11
推荐指数
3
解决办法
2万
查看次数

在网格视图中显示图像的最佳方式是滚动平滑

首先,我已经做了很少的事情来在gridview中显示图像,使滚动时变得平滑

1.从背景线程上的互联网加载图像

AsyncTask acyncTask ;
HandlerThread handlerThread ;

 URL imageUrl = new URL(link);<br>
            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
            conn.setConnectTimeout(30000);
            conn.setReadTimeout(30000);
            conn.setInstanceFollowRedirects(true);
            InputStream is=conn.getInputStream();
            final Bitmap bitmap = BitmapFactory.decodeStream(is);
Run Code Online (Sandbox Code Playgroud)

2.将位图设置为样本大小以节省内存

final BitmapFactory.Options option = new BitmapFactory.Options();
    option.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mFile.getPath(),
            option);
    option.inSampleSize = calculateInSampleSize(option , mSize , mSize);
    option.inJustDecodeBounds = false;
    option.inPurgeable = true ;
    option.inDither = false ;
    option.inScaled = false ;
    option.inPreferredConfig = Bitmap.Config.ARGB_8888;
Run Code Online (Sandbox Code Playgroud)

3.制作缓存以保存解码的位图

LruCache lruCache = new LruCache<String , Bitmap>();
Run Code Online (Sandbox Code Playgroud)

baseadapter getView(); 我将lruCache.get(key)采取解码的位图

4.通过处理程序解码位图时的延迟加载

 Handler …
Run Code Online (Sandbox Code Playgroud)

performance android bitmap

5
推荐指数
1
解决办法
1万
查看次数

循环效率比较

哪个更有效?:

ArrayList<Integer> list = new ArrayList<Integer>();
for(int a : list){
   log.i(tag, a + "");
}

SparseIntArray list2 = new SparseIntArray();
int count = list2.size();
for(int j = 0; j < count; j++) {
   log.i(tag, list2.get(j) + "");
}
Run Code Online (Sandbox Code Playgroud)

或者,是否有更快的方式来读取列表的内容?

performance android loops arraylist

1
推荐指数
1
解决办法
1949
查看次数