我之前在少数设备上测试了我的应用。 Genymotion(nexus 4 api 16),samsung i9500(api 21),samsung i8190(api 16),nexus 9(api 23),全部工作。但是今天我在三星i8262(api 16)上尝试了测试应用程序,并且在我的应用程序中遇到所有回收站视图中的滚动工作。大多数带有recycler视图的xml都将它作为root和single元素。我不是在看这个问题的原因。有人见过同样的事吗?
public class NewsFragment extends Fragment {
int currentLastArticle = 0;
int count;
ArrayList<Article> news = new ArrayList<>();
View view;
RecyclerView rv;
LinearLayoutManager llm;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.recycler_view, container, false);
view.setPadding(0, Decorator.getHeightBasedOnIPhone960(89), 0, 0);
rv = (RecyclerView) view.findViewById(R.id.recycler);
llm = new LinearLayoutManager(activity);
rv.setLayoutManager(llm);
rv.addItemDecoration(new Divider(activity));
rv.setOnScrollListener(new EndlessRecyclerScrollListener(llm) {
@Override
public void onLoadMore(int current_page) {
new GetNewsTask().execute(20, currentLastArticle+=20);
}
});
new GetNewsTask().execute(20, currentLastArticle);
return view;
}
class NewsRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
LayoutInflater inflater;
public NewsRecyclerAdapter(Context context) {
inflater = ((AppCompatActivity)context).getLayoutInflater();
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new NewsVH(inflater.inflate(R.layout.news_item, parent, false));
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
((NewsVH)holder).set(position);
}
@Override
public int getItemCount() {
return news.size();
}
private class NewsVH extends RecyclerView.ViewHolder{
Text title;
Text time;
ImageView image;
View itemView;
public NewsVH(View itemView) {
super(itemView);
this.itemView = itemView;
itemView.setPadding(
Decorator.getWidthBasedOnIPhone640(8),
Decorator.getHeightBasedOnIPhone960(8),
Decorator.getWidthBasedOnIPhone640(8),
Decorator.getHeightBasedOnIPhone960(8)
);
init(itemView);
}
private void init(View view) {
title = (Text) view.findViewById(R.id.title);
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, Decorator.getHeightBasedOnIPhone960(24));
Decorator.setMargins(title, 0, 8, 0, 0);
time = (Text) view.findViewById(R.id.time);
time.setTextSize(TypedValue.COMPLEX_UNIT_PX, Decorator.getHeightBasedOnIPhone960(20));
time.setTextStyle(font.font133l);
image = (ImageView) view.findViewById(R.id.image);
image.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Decorator.setSquareSizeAndMargins(image, 176, 0, 0, 8, 8);
}
public void set(final int position) {
Article article = news.get(position);
title.setText(article.title());
time.setText(article.time());
String image = article.files().length == 0 ? "null" : article.files()[0].url480();
ImageLoader.getInstance().displayImage(image, this.image, Decorator.getImageOptions(svg.zelen.drawable()));
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArticleFragment fragment = new ArticleFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(getString(R.string.article), news.get(position));
fragment.setArguments(bundle);
activity.getSupportFragmentManager()
.beginTransaction()
.addToBackStack(Flags.CATALOG_BACKSTACK)
.replace(R.id.container, fragment, fragment.getClass().getCanonicalName())
.commit();
}
});
}
}
}
class GetNewsTask extends AsyncTask<Integer, String, JSONArray> {
int lowTreshold;
int highTreshold;
@Override
protected void onPreExecute() {
((ProgressSwitcher)activity).showProgress();
}
@Override
protected JSONArray doInBackground(Integer... params) {
lowTreshold = params[1];
highTreshold = params[0];
String newsString = Web.httpGet(
Web.url.domain +
Web.url.content +
"/" +
highTreshold +
"/" +
lowTreshold
);
JSONArray jNewsArray = new JSONArray();
try {
JSONObject jNews = new JSONObject(newsString);
jNewsArray = jNews.getJSONArray("content");
count = jNews.getInt("count");
} catch (JSONException e) {
e.printStackTrace();
}
return jNewsArray;
}
@Override
protected void onPostExecute(JSONArray jArray) {
((ProgressSwitcher)activity).hideProgress();
int length = jArray.length();
for (int i = 0; i < length; i++) {
try {
news.add(new Article(jArray.getJSONObject(i)));
} catch (JSONException e) {
e.printStackTrace();
}
}
if (rv.getAdapter() == null) {
rv.setAdapter(new NewsRecyclerAdapter(activity));
} else {
rv.getAdapter().notifyDataSetChanged();
}
}
}
}
例如,。 R.layout.recyclerview是
<android.support.v7.widget.RecyclerView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/white"
android:id="@+id/recycler"
xmlns:android="http://schemas.android.com/apk/res/android" />
它是我应用中的众多回收商之一。他们一切都不滚动。