**
一言不合就上图
**

我的AS版本是:3.1.2
android版本是:19——27
首先依賴(僅供參考):
//recyclerview
implementation 'com.android.support:recyclerview-v7:27.1.1'
然後項目結構:

首先:activity_main.xml的佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:text="下面是recycler View點擊變色demo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10px"
android:orientation="horizontal"
android:padding="20px">
<android.support.v7.widget.RecyclerView
android:id="@+id/recView"
android:layout_width="300px"
android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
<TextView
android:id="@+id/right_titel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="30px"
android:background="@color/colorAccent"
android:gravity="center"
android:text="點擊左側 獲取值"
android:textSize="33sp" />
</LinearLayout>
</LinearLayout>
recview_item.xml的佈局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android

本文介绍了如何在Android中为RecyclerView和ListView实现点击变色及更换背景颜色的效果,提供了activity_main.xml、recview_item.xml的布局示例,以及RecViewAdapter和MainActivity的代码示例,附带了完整的Demo。
最低0.47元/天 解锁文章
685

被折叠的 条评论
为什么被折叠?



