2024年3月9日发(作者:)
1 package eviewdemo;
2
3 import patActivity;
4 import ;
5 import tItemAnimator;
6 import LayoutManager;
7 import erView;
8
9 import ist;
10 import ;
11
12 public class MainActivity extends AppCompatActivity {
13
14 private RecyclerView mRecyclerView;
15 private LinearLayoutManager mLinearLayoutManager;
16 private RecycleViewAdapter mRecycleViewAdapter;
17
18 private List
19
20 @Override
21 protected void onCreate(Bundle savedInstanceState) {
22 te(savedInstanceState);
23 setContentView(ty_main);
24
25 bindViews();
26 initData();
27 //初始化线性布局管理器
28 mLinearLayoutManager = new LinearLayoutManager(this);
29 //设置布局管理器
30 outManager(mLinearLayoutManager);
31 mAnimator(new DefaultItemAnimator());
32 //初始化适配器
33 mRecycleViewAdapter = new RecycleViewAdapter(mData);
34 //设置适配器
35 pter(mRecycleViewAdapter);
36 }
37
38 private void bindViews() {
39 mRecyclerView = findViewById(e_view);
40 }
41
42 private void initData() {
43 mData = new ArrayList<>();
44 (new Item(r, "The Witcher 3: Wild Hunt"));
45 (new Item(, "Recore"));
46 (new Item(s, "Assassin's Creed Origins"));
47 (new Item(, "theHunter: Call of the Wild"));
48 }
49 }
Item布局:
1
2 3 xmlns:android="/apk/res/android" 4 xmlns:app="/apk/res-auto" 5 xmlns:tools="/tools" 6 android:orientation="vertical" 7 android:layout_width="match_parent" 8 android:layout_height="wrap_content" 9 android:layout_margin="4dp" 10 android:elevation="2dp" 11 android:background="@drawable/background_item"> 12 13 14 android:id="@+id/image_view" 15 android:contentDescription="@null" 16 android:layout_width="0dp" 17 android:layout_height="235dp" 18 android:layout_margin="6dp" 19 tools:src="@drawable/witcher" 20 app:layout_constraintTop_toTopOf="parent" 21 app:layout_constraintStart_toStartOf="parent" 22 app:layout_constraintEnd_toEndOf="parent" /> 23 24 25 android:id="@+id/text_title" 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:textSize="18sp" 29 android:textColor="#000000" 30 android:layout_margin="6dp" 31 android:paddingBottom="4dp" 32 app:layout_constraintTop_toBottomOf="@+id/image_view" 33 app:layout_constraintStart_toStartOf="parent" 34 app:layout_constraintBottom_toBottomOf="parent" 35 tools:text="The Witcher 3: Wild Hunt" /> 36 37
MainActivity布局:
1
2 3 xmlns:app="/apk/res-auto" 4 xmlns:tools="/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity"> 8 9 10 android:id="@+id/toolbar" 11 android:layout_width="match_parent" 12 android:layout_height="48dp" 13 android:background="@color/colorPrimary" 14 android:elevation="5dp" 15 app:layout_constraintEnd_toEndOf="parent" 16 app:layout_constraintStart_toStartOf="parent" 17 app:layout_constraintTop_toTopOf="parent"> 18 19 20 android:contentDescription="@null" 21 android:layout_width="36dp" 22 android:layout_height="36dp" 23 android:src="@drawable/icon" /> 24 25 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:layout_gravity="center" 29 android:text="@string/app_name" 30 android:textColor="#FFFFFF" 31 android:textSize="18sp" /> 32 33 34 35 36 android:id="@+id/recycle_view" 37 android:layout_width="0dp" 38 android:layout_height="0dp" 39 app:layout_constraintBottom_toBottomOf="parent" 40 app:layout_constraintEnd_toEndOf="parent" 41 app:layout_constraintStart_toStartOf="parent" 42 app:layout_constraintTop_toBottomOf="@+id/toolbar" 43 app:layout_constraintVertical_bias="1.0"> 44 45 46 47


发布评论