recyclerView

This commit is contained in:
Rao 2024-06-15 00:26:43 +08:00
parent 400f6bfa8b
commit 8151d0d807
17 changed files with 449 additions and 52 deletions

View File

@ -38,4 +38,13 @@ dependencies {
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
implementation ("io.github.youth5201314:banner:2.2.3")
implementation ("com.github.bumptech.glide:glide:4.15.1")
implementation("com.squareup.okhttp3:okhttp:4.11.0")
implementation ("io.github.scwang90:refresh-layout-kernel:2.1.0") //核心必须依赖
implementation ("io.github.scwang90:refresh-header-classics:2.1.0") //经典刷新头
implementation ("io.github.scwang90:refresh-header-radar:2.1.0") //雷达刷新头
implementation ("io.github.scwang90:refresh-header-falsify:2.1.0") //虚拟刷新头
implementation ("io.github.scwang90:refresh-header-material:2.1.0") //谷歌刷新头
implementation ("io.github.scwang90:refresh-header-two-level:2.1.0") //二级刷新头
implementation ("io.github.scwang90:refresh-footer-ball:2.1.0") //球脉冲加载
implementation ("io.github.scwang90:refresh-footer-classics:2.1.0")
}

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:usesCleartextTraffic="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
@ -13,7 +13,11 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CurriculumDesign"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".HomeActivity2"
android:exported="false" />
<activity
android:name=".HomeActivity"
android:exported="false" />

View File

@ -0,0 +1,8 @@
package com.hnucm.c202201020141;
public class Chat {
public String name;
public String content;
public String time;
public String imgurl;
}

View File

@ -0,0 +1,133 @@
package com.hnucm.c202201020141;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import java.util.ArrayList;
import java.util.List;
public class HomeActivity2 extends AppCompatActivity {
RecyclerView recyclerView;
SmartRefreshLayout smartRefreshLayout;
MyAdpater myAdpater;
List<Chat> chatList=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0;i<20;i++){
Chat chat=new Chat();
chat.name="姓名"+i;
chat.content="聊天内容"+i;
chat.time="聊天时间"+i;
chatList.add(chat);
}
recyclerView=findViewById(R.id.recyclerView);
smartRefreshLayout=findViewById(R.id.smartlayout);
//设置下拉上拉样式
smartRefreshLayout.setRefreshHeader(new ClassicsHeader(this));
smartRefreshLayout.setRefreshFooter(new ClassicsFooter(this));
smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh(@NonNull RefreshLayout refreshLayout) {
//清除原来数据
smartRefreshLayout.finishRefresh();
chatList.clear();
//构造一些数据 ->todo 网络请求得到
for(int i=0;i<20;i++){
Chat chat=new Chat();
chat.name="姓名"+i;
chat.content="聊天内容"+i;
chat.time="聊天时间"+i;
chatList.add(chat);
}
smartRefreshLayout.finishRefresh(2000);
//更新列表页面数据
myAdpater.notifyDataSetChanged();
}
});
smartRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
//上拉加载
for(int i=0;i<20;i++){
Chat chat=new Chat();
chat.name="姓名"+i;
chat.content="聊天内容"+i;
chat.time="聊天时间"+i;
chatList.add(chat);
}
smartRefreshLayout.finishLoadMore(2000);
//更新列表页面数据
myAdpater.notifyDataSetChanged();
}
});
myAdpater=new MyAdpater();
recyclerView.setAdapter(myAdpater);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
public class MyViewHolder extends RecyclerView.ViewHolder{
TextView textView;
TextView textView2;
TextView textView3;
ConstraintLayout Layout;
public MyViewHolder(@NonNull View itemView){
super((itemView));
textView=itemView.findViewById(R.id.textView);
textView2=itemView.findViewById(R.id.textView2);
textView3=itemView.findViewById(R.id.textView3);
Layout=itemView.findViewById(R.id.Layout);
}
}
public class MyAdpater extends RecyclerView.Adapter<MyViewHolder>{
//加载布局文件
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view= LayoutInflater.from(HomeActivity2.this).inflate(R.layout.chat_item_layout,parent,false);
return new MyViewHolder(view);
}
//修改item中控件的值 按需加载
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
Chat chat=chatList.get(position);
holder.textView.setText(chatList.get(position).name);
holder.textView2.setText(chatList.get(position).content);
holder.textView3.setText(chatList.get(position).time);
holder.Layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(HomeActivity2.this, ChatActivity.class);
intent.putExtra("name",chat.name);
startActivity(intent);
}
});
}
//显示item的条数
@Override
public int getItemCount() {
return chatList.size();
}
}
}

View File

@ -1,5 +1,7 @@
package com.hnucm.c202201020141;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@ -7,59 +9,57 @@ import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import java.util.ArrayList;
import java.util.List;
/**
* A simple {@link Fragment} subclass.
* Use the {@link HomeFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class HomeFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
public HomeFragment() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment HomeFragment.
*/
// TODO: Rename and change types and number of parameters
public static HomeFragment newInstance(String param1, String param2) {
HomeFragment fragment = new HomeFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
View view= inflater.inflate(R.layout.fragment_home, container, false);
Banner banner=view.findViewById(R.id.banner);
List<String>list=new ArrayList<>();
list.add("http://106.53.194.250:30089/i/2024/06/14/666bd10fa2310.png");
list.add("https://img.youjidi.net/uploadimg/image/20200118/20200118093534_87353.jpg");
list.add("https://img95.699pic.com/element/40138/8242.png_860.png");
banner.setAdapter(new BannerImageAdapter<String>(list) {
@Override
public void onBindView(BannerImageHolder holder, String data, int position, int size) {
//Glide 网络地址 ->添加网络请求权限
Glide.with(holder.itemView)
.load(data)
.into(holder.imageView);
}
});
banner.setIndicatorRadius(100);
TextView textView27=view.findViewById(R.id.textView27);
textView27.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(getActivity(),HomeActivity2.class);
startActivity(intent);
}
});
return view;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".HomeActivity2">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="409dp"
android:layout_height="580dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView24">
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/smartlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:id="@+id/imageView24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="76dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/_2024_06_14_191105" />
<ImageView
android:id="@+id/imageView25"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/_2024_06_14_191544" />
<TextView
android:id="@+id/textView28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="专家分类"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -217,8 +217,9 @@
android:id="@+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="44dp"
android:text="通过注册我同意Online.C的 服务条款和隐私政策"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="671dp" />
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/Layout"
android:layout_width="match_parent"
android:layout_height="150dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_launcher_background" />
<TextView
android:id="@+id/textView"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_marginStart="24dp"
android:layout_marginTop="4dp"
android:text="TextView"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="@+id/imageView" />
<TextView
android:id="@+id/textView2"
android:layout_width="80dp"
android:layout_height="20dp"
android:layout_marginStart="24dp"
android:layout_marginTop="20dp"
android:text="TextView"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<TextView
android:id="@+id/textView3"
android:layout_width="80dp"
android:layout_height="20dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="40dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,14 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".HomeFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="home" />
android:layout_height="match_parent">
<com.youth.banner.Banner
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.141" />
<ImageView
android:id="@+id/imageView16"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="20dp"
android:src="@drawable/_7"
app:layout_constraintEnd_toStartOf="@+id/imageView15"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="32dp"
android:text="Online.C"
android:textColor="#0A94FF"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView15"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="16dp"
android:src="@drawable/_4__1_"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView26"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:text="专家分类"
android:textColor="#404446"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/banner" />
<TextView
android:id="@+id/textView27"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="16dp"
android:text="查看全部"
android:textColor="#FF7360"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/banner" />
<ImageView
android:id="@+id/imageView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/_2024_06_14_150147"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/imageView19"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/imageView17"
app:layout_constraintTop_toBottomOf="@+id/banner"
app:layout_constraintVertical_bias="0.225" />
<ImageView
android:id="@+id/imageView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/_2024_06_14_150153"
app:layout_constraintBottom_toBottomOf="@+id/imageView18"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/imageView18"
app:layout_constraintTop_toTopOf="@+id/imageView18" />
<ImageView
android:id="@+id/imageView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:src="@drawable/_2024_06_14_150343"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView18"
app:layout_constraintVertical_bias="0.391" />
<ImageView
android:id="@+id/imageView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/_2024_06_14_150140"
app:layout_constraintBottom_toBottomOf="@+id/imageView18"
app:layout_constraintEnd_toStartOf="@+id/imageView18"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView18"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>