我制作的应用程序有几个电影屏幕,其中一个是从imdbs前250名电影列表中加载的。我试图在卡加载时实现动画,但无济于事。最终,我将问题缩小到数据集如此之大的事实。当我将变量loadHowMany更改为25或更少时,动画加载正常。我是否必须实现某种无限滚动功能,或者是否有办法为这个大型数据集设置动画?
Top250Activity.java
glUniform1i
item_animation_fall_down.xml
public class Top250Activity extends BaseActivity {
private RecyclerView mListView;
JSONArray array;
Movie[] searchResults;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_top250);
mListView = findViewById(R.id.top250list);
mListView.setNestedScrollingEnabled(false);
try {
getResults(new Runnable() {
@Override
public void run() {
final MovieCardAdapter adapter = new MovieCardAdapter(getApplicationContext(), searchResults);
runOnUiThread(new Runnable() {
@Override
public void run() {
LinearLayoutManager lLayout;
mListView.setNestedScrollingEnabled(false);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.item_animation_fall_down);
mListView.setAnimation(animation);
lLayout = new GridLayoutManager(Top250Activity.this, 2);
mListView.setHasFixedSize(true);
mListView.setLayoutManager(lLayout);
mListView.setAdapter(adapter);
}
});
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
private void getResults(final Runnable runnable) throws JSONException {
final String apiKey = #######;
final int loadHowMany = 100;
String theURL = "https://api.morph.io/btrav528/imdb-top-250/data.json?key=#############&query=select%20*%20from%20%22data%22%20limit%20" + loadHowMany;
final OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(theURL).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NonNull Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
final String jsonData = response.body().string();
JSONObject results;
try {
array = new JSONArray(jsonData);
searchResults = new Movie[array.length()];
for (int i = 0; i < array.length(); i++) {
JSONObject jsonResult = array.getJSONObject(i);
final Movie movie = new Movie();
String html = jsonResult.getString("name");
String title = Html.fromHtml(html).toString();
movie.setTitle(title);
movie.setYear(jsonResult.getString("year"));
Uri uri = Uri.parse(jsonResult.getString("link"));
String path = uri.getPath();
Log.d("taggie", path);
String[] segments = uri.getPath().split("/");
String idStr = segments[segments.length-1];
Log.d("taggieidstr", idStr);
String posterUrl = "http://img.omdbapi.com/?i=" + idStr + "&h=600&apikey=" + apiKey;
movie.setPosterURL(posterUrl);
movie.setImdbID(idStr);
searchResults[i] = movie;
}
runnable.run();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
答案 0 :(得分:1)
我认为通过无限滚动实现它更好。 一个有用的链接: https://camposha.info/source/android-sqlite-recyclerview-infiniteendless-paginationload-serverside