Android开发中遇到的问题记录

1.在写LinearLayout的时候一定要显示写orientation,不然有时候编辑器不提示你,然后遇到方向的问题你就囧了.


2.获取手机中多有图片并按文件夹分类
----可以通过一次读完数据库中全部图片自己分类
----可以通过下面的方法group by直接查询文件夹信息
String[] projection = new String[]{BaseColumns._ID,
                MediaStore.Images.ImageColumns.BUCKET_ID, MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
                MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.DATA,
                "count(" + BaseColumns._ID + ")"};
String selection = " 0==0) group by bucket_display_name --(";
Cursor cursor = getActivity().getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
                selection, null, "");
FileInfo mFileInfo;
        while (cursor.moveToNext()) {
            String folderId = cursor.getString(cursor
                    .getColumnIndex(ImageColumns.BUCKET_ID));
            String folder = cursor.getString(cursor
                    .getColumnIndex(ImageColumns.BUCKET_DISPLAY_NAME));
            long fileId = cursor
                    .getLong(cursor.getColumnIndex(BaseColumns._ID));
            String path = cursor.getString(cursor
                    .getColumnIndex(MediaColumns.DATA));
            int count = cursor.getInt(5);// 该文件夹下一共有多少张图片
            BitmapFactory.Options options = new BitmapFactory.Options();
            mFileInfo = new FileInfo();
            mFileInfo.count = count;
            mFileInfo.fileId = folderId;
            mFileInfo.dbId = fileId;
            mFileInfo.filePath = path;
            mFileInfo.fileName = folder;
            datas.add(mFileInfo);
        }

然后每次用的时候再通过文件夹去查询图片
private Cursor getPhotoByBucketId(String bukcetId) {
        Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        String selection = MediaStore.Images.Media.MIME_TYPE + "=? OR " + MediaStore.Images.Media.MIME_TYPE + "=?";
        if (bukcetId != null && !"-1".equals(bukcetId)) {
            selection = ImageColumns.BUCKET_ID + "=" + bukcetId + " AND (" + selection + ")";
        }
        String sortOrder = MediaColumns.DATE_MODIFIED + " desc";
        String[] columns = new String[]{BaseColumns._ID, MediaColumns.DISPLAY_NAME,
                MediaColumns.DATA, MediaColumns.SIZE};

        Cursor cursor = this.getContentResolver().query(uri, columns,
                selection, new String[]{"image/jpeg", "image/png"}, sortOrder);
        return cursor;

    }


3.scrollview --- fillViewport

t must be set to ScrollView and has the following efect : when set to true, this attribute causes the scroll view’s child to expand to the height of the ScrollView if needed. When the child is taller than the ScrollView, the attribute has no effect.

当你想让一个高度值不足scrollview的子控件fillparent的时候,单独的定义android:layout_height="fill_parent"是不起作用的,必须加上fillviewport属性,当子控件的高度值大于scrollview的高度时,这个标签就没有任何意义了。


4.自定义View的时候,如果要在xml中声明,需要实现三个父类的构造方法.如果你有initview之类的方法来初始化自己的view,那么只要在第三个方法中如
public BannerView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }
中放入initView(context);即可,因为前两个构造方法最后都是调用的第三个,如果都放会重复调用.

5.android.content.res.Resources$NotFoundException: String resource ID #0xa
很多方法都有重载方法,比如TextView的setText(CharSequence text)和setText(int resId),如果你穿int值就可能会报上面这个异常

6.对于thrift一定要用set方法,不然在序列化的时候会有问题

7.在使用代码创建文件的时候,只能在一个已存在的文件夹下创建文件,不然会创建失败,如果需要创建多级文件夹,需要逐级往下创建文件夹,然后在创建文件

8.如果你改变了应用在手机桌面上的图片而没有效果,那么可以清理下桌面的缓存再试就好了.

9.用ubuntu解压出现乱码,可以使用unzip -O CP936 xxxx.zip 来手动解压

10.使用SwipeListView中的坑,最好在点击backView后立即调用closeOpenedItems,不然可能会出现奇怪的问题,如:frontView已经关掉,但是实际上还可以点击backView的情况.

猜你喜欢

转载自blog.csdn.net/myterabithia/article/details/50750138