リソースから読み込んでいるカードビューが1つしかないカードビューを含む単純なリサイクラビューを持っていますが、とにかくスクロールしている間に強いラグがある、recycler.setHasFixedSize(true)助けにならない。RecyclerViewのスクロールが単純なアイテム
Acitivityコード
public class MainActivity extends AppCompatActivity {
private final int[] drawables = {
R.drawable.nxt_bluetooth_dongle,
R.drawable.color_sensor,
R.drawable.connector_cabels,
R.drawable.e_motor,
R.drawable.energy_storage,
R.drawable.energy_display,
R.drawable.gyroscopic_sensor,
R.drawable.intelligent_nxt_brick,
R.drawable.keyfob_transponder,
R.drawable.light_sensor,
R.drawable.motion_sensor,
R.drawable.nxt_ir_receiver,
R.drawable.nxt_light_sensor,
R.drawable.nxt_servo_motor,
R.drawable.nxt_sound_sensor,
R.drawable.nxt_touch_sensor,
R.drawable.nxt_ultrasonic_sensor,
R.drawable.rf_id_sensor,
R.drawable.solar_panel,
R.drawable.tilt_sensor,
R.drawable.temperature_sensor,
R.drawable.usb_hub
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recycler = (RecyclerView) findViewById(R.id.recycler);
MyAdapter adapter = new MyAdapter(drawables);
recycler.setAdapter(adapter);
recycler.setLayoutManager(new GridLayoutManager(this, 3));
}
private class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyHolder> {
private int[] drawables;
private MyAdapter(int[] drawables) {
this.drawables = drawables;
}
@Override
public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.lego_recycler_item, null, false);
return new MyHolder(view);
}
@Override
public void onBindViewHolder(MyHolder holder, int position) {
holder.legoImage.setImageResource(drawables[position]);
}
@Override
public int getItemCount() {
return drawables.length;
}
class MyHolder extends RecyclerView.ViewHolder {
ImageView legoImage;
MyHolder(View itemView) {
super(itemView);
legoImage = (ImageView) itemView.findViewById(R.id.legoImage);
legoImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, LegoDetailActivity.class);
intent.putExtra(LegoDetailActivity.EXTRA_DRAWABLE_ID, drawables[getAdapterPosition()]);
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
MainActivity.this, legoImage, "legoDetail"
);
startActivity(intent, options.toBundle());
}
});
}
}
}
}
活動XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e0e0e0"
tools:context="com.lol.legomindstorms.MainActivity">
</android.support.v7.widget.RecyclerView>
リサイクラー項目のXML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardUseCompatPadding="true"
app:cardCornerRadius="0dp">
<ImageView
android:id="@+id/legoImage"
android:layout_width="115dp"
android:layout_height="115dp"
android:transitionName="legoDetail" />
</android.support.v7.widget.CardView>
ピカソまたはグライドを試してみてください。 –
@DivyeshPatelが述べたように、画像のロードである可能性があります。上記の2つのライブラリは、UIスレッドから作業を取り除き、スムーズなエクスペリエンスを実現します。 これらの画像のサイズと解像度を確認することをお勧めします。それはディスク上で4kbかもしれませんが、実際にはLxWx4またはLxW *(AARRGGBB)です。 – tricknology
私の答え[ここ](http://stackoverflow.com/a/43219866/7292819)を参照してください。あなたの問題に役立つかもしれません。 – Gary99