如何preVIEW R.drawable。*图片图片、preVIEW、drawable

2023-09-05 06:54:29 作者:啃为你疯狂╭ァ

Android框架具有各种图标和图像 - 访问作为R.drawable * - 可用于通过常见任务的应用程序。他们的名字给什么,他们有一些暗示,但在许多情况下,这是不够的。一个人使用试验正误差找到合适的图标,适合一个人的目的。

Android framework has variety of icons and images - accessible as R.drawable.* - that can be used by applications for common tasks. Their names give some hint about what they are, but in many cases that's not sufficient. One has to use trial-n-error to find the right icon that fits one's purpose.

我的问题:有没有一种方法,我可以在一个地方preVIEW所有这些图像,这样我就可以快速地决定使用哪些

My question: Is there a way where I can preview all these images in one place, so that I can quickly decide which ones to use?

我已经看过里面的Andr​​oid源$ C ​​$ C,但无法找到这些可绘制的根源。

I have looked inside android source code, but couldn't locate the root of these drawables.

让我知道,如果你们有什么秘诀。 谢谢你。

Let me know if any of you have any tips. Thanks.

推荐答案

由于科里,这是pretty的太多我一直在寻找。与此同时,虽然,我做一个小的应用程序,以preVIEW所有可绘制。这是一个小的应用程序,它使用反射来列出所有可绘制(图像preVIEW他们的名字),如在这个屏幕截图。

Thanks Corey, that's pretty much what I was looking for. Meanwhile though, I cooked a small app to preview all the drawables. It's a small app which uses reflection to list all the drawables (image preview and their names) as shown in this screen shot.

它基本上遵循code片断:

It's basically following code snippet:

public class DrawablePreviewActivity extends ListActivity
{
    private static final String TAG = "DrawablePreviewActivity";

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setTitle("Preview of android.R.drawable.*");

        try {
            Class RClass = Class.forName("android.R");

            Class[] subclasses = RClass.getDeclaredClasses();

            Class RDrawable = null;

            for(Class subclass : subclasses) {
                if("android.R.drawable".equals(subclass.getCanonicalName())) {
                    RDrawable = subclass;
                    break;
                }
            }

            List<Map<String, Object>> drinfo = new ArrayList<Map<String, Object>>();

            Field[] drawables = RDrawable.getFields();
            for(Field dr : drawables) {
                Map<String, Object> map = new HashMap<String, Object>();
                Drawable img = getResources().getDrawable(dr.getInt(null));

                map.put("drimg", dr.getInt(null));
                map.put("drname", dr.getName());

                drinfo.add(map);
            }

            setListAdapter(new SimpleAdapter(this,
                            drinfo,
                            R.layout.listitem,
                            new String[] { "drimg", "drname" },
                            new int[] { R.id.drimg, R.id.drname }));

        } catch(IllegalAccessException iae) {
            Log.e(TAG, iae.toString());
        } catch(ClassNotFoundException cnfe) {
            Log.e(TAG, cnfe.toString());
        }
    }
}

您还可以从一个源码包http://www.altcanvas.com/downloads/drawable$p$pview.tar.gz

You can also get a source tarball from http://www.altcanvas.com/downloads/drawablepreview.tar.gz

或http://www.altcanvas.com/downloads/apks/drawable$p$pview.apk

 
精彩推荐
图片推荐