parseQuery scrollview skipframe

时间:2015-09-29 17:00:09

标签: android parse-platform scrollview

我有一个scrollview,其内容我使用ParseQuery中的文件填充。scrollView的内容加载没有任何问题。然而,当我滚动时,它变得迟钝并且每个滑块移动跳过50-100帧。

我使用AsyncTaskRunner从parse运行查询。如果我对滚动视图的内容进行硬编码,则不再跳过帧。

我无法弄清问题是什么。滚动时我没有进行任何ParseQuery - 所以逻辑上不应该因为parseQuery而出现跳帧问题。

这是我的xml布局文件。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.app.method">

<TextView android:id="@+id/heading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textStyle="italic|bold"/>


<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/heading">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:layout_gravity="center_horizontal"/>


<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/body"
    android:textSize="15dp"
    android:textStyle="normal"/>

</LinearLayout>


</ScrollView>
</RelativeLayout>

这是我的查询代码。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.method);
    tv = (TextView) findViewById(R.id.heading);
    AsyncTaskA runner = new AsyncTaskA();
    runner.execute();

}


public class AsyncTaskA extends AsyncTask<Void, Void, Void > {

    @Override
    protected Void doInBackground(Void... params) {
        ParseQuery<ParseObject> itemsByCategory = new ParseQuery<ParseObject>("ClassA");
        itemsByCategory.fromLocalDatastore();
        itemsByCategory.ignoreACLs();
        itemsByCategory.whereEqualTo("variable", ParseUser.getCurrentUser().getString("variableID"));
        try {
            itemList = itemsByCategory.find();
        } catch (com.parse.ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        String [] items= new String [ itemList.size() ];

        for (int x=0; x<itemList.size();x++)
        {
            items[x] = itemList.get(x).getString("itemName");
        }


        ParseQuery<ParseObject> query = ParseQuery.getQuery("ClassB");
        query.whereContainedIn("mainItem", Arrays.asList(items));

        try {
            currentList = query.find();
        } catch (com.parse.ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        if(currentList.size()>0) {
            obj = currentList.get(0);
            obj.pinInBackground();
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // execution of result of Long time consuming operation
        ParseQuery<ParseObject> query = ParseQuery.getQuery("ClassB");
        query.fromLocalDatastore();
        query.ignoreACLs();

        try {
            currentList2 = query.find();
            obj2 = currentList2.get(0);

        } catch (com.parse.ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        tv.setText(obj2.getString("Title"));
        image = obj2.getParseFile("image2");

        image.getDataInBackground(new GetDataCallback() {
            @Override
            public void done(byte[] data, com.parse.ParseException e) {
                if (e == null) {
                    Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);

                    if (bmp != null) {
                        ImageView iv = (ImageView) findViewById(R.id.imageView);
                        iv.setImageBitmap(bmp);
                    }
                } else {
                    Log.d("Error", e.getMessage());
                }
            }
        });

        body = obj2.getParseFile("text_file");


        recipebody.getDataInBackground(new GetDataCallback() {
            @Override
            public void done(byte[] data, com.parse.ParseException e) {
                String fileContent = new String(data);

                TextView body = (TextView) findViewById(R.id.body);
                recipeB.setText(fileContent);
            }
        });
    }

    @Override
    protected void onPreExecute() {
    }

    @Override
    protected void onProgressUpdate(Void... text) {
    }
}

0 个答案:

没有答案