У меня есть вид сетки с 32 элементами или изображениями. Изображения довольно низкого качества и не более 300 КБ. Каждый раз, когда я прокручиваю, вид сетки отстает, и он заметно заметно. Я хотел бы получить идеи или реальный код о том, что делать дальше.
Я пытался сделать изображения еще более низкого качества, но это не помогло. Только если я использую одно изображение для всех 32 элементов в виде сетки, все отлично работает, но как только у меня появляется больше разных изображений, оно отстает.
мой класс:
private GridView gridView;
ArrayList<CreateProduct> products;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);setContentView(R.layout.activity_all_products_grid_view);
products = new ArrayList<CreateProduct>();
createAllProducts2();
gridView = (GridView) findViewById(R.id.allProductGrid);
GridAdapter customAdapter = new GridAdapter(this, products);
gridView.setAdapter(customAdapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
CreateProduct x = products.get(i);
goToProductDetails(x.productName, x.id, x.productDesc,x.productKulise, x.image);
}
});
}
мой адаптер:
public class GridAdapter extends BaseAdapter {
ArrayList<CreateProduct> arrayGrid;
Context context;
public GridAdapter(Context context, ArrayList<CreateProduct> arrayList){
this.arrayGrid = arrayList;
this.context = context;
}
@Override
public int getCount() {
return arrayGrid.size();
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
final CreateProduct product = arrayGrid.get(i);
if (view == null){
final LayoutInflater layoutInflater = LayoutInflater.from(context);
view = layoutInflater.inflate(R.layout.grid_row, null);
}
final TextView title33 = view.findViewById(R.id.titleGrid);
final ImageView image33 = view.findViewById(R.id.grid_image);
title33.setText(product.productName);
image33.setImageResource(product.image);
return view;
}
}
ma grid_row xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/grid_image"
android:layout_gravity="center"
android:layout_width="130sp"
android:layout_height="130sp"
android:contentDescription="@string/comment_button_product_details"
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:id="@+id/titleGrid"
android:layout_width="130sp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/product_name"
android:textAlignment="center" />
</LinearLayout>
Я не получаю никаких сообщений об ошибках. Я бы хотел, чтобы вид сетки не отставал.