Loading

在微信界面中对recycleView的页面进行点击跳转设计-ZTY

这次我们要实现给我们的微信界面中的recycleView进行点击跳转到其他activity的操作

首先我们先创建3个新的activity,分别对应点击华为,苹果,小米是跳转的activity

 

 然后在这三个activity对应的xml文件中输入详细的参数,实现点击跳转后会显示详细的信息的功能

 

具体代码:

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     xmlns:app="http://schemas.android.com/apk/res-auto"
  4     xmlns:tools="http://schemas.android.com/tools"
  5     android:layout_width="match_parent"
  6     android:layout_height="match_parent"
  7     tools:context=".MainActivity4">
  8 
  9     <TextView
 10         android:id="@+id/textView12"
 11         android:layout_width="match_parent"
 12         android:layout_height="match_parent"
 13         android:layout_weight="1"
 14         android:gravity="center"
 15         android:text="华为手机具体参数:"
 16         android:textSize="30sp" />
 17 
 18     <LinearLayout
 19         android:layout_width="221dp"
 20         android:layout_height="match_parent"
 21         android:orientation="vertical">
 22 
 23         <TextView
 24             android:id="@+id/text_view5"
 25             android:layout_width="match_parent"
 26             android:layout_height="wrap_content"
 27             android:layout_marginLeft="1dp"
 28             android:layout_marginTop="1dp"
 29             android:layout_marginRight="1dp"
 30             android:layout_marginBottom="1dp"
 31             android:layout_weight="1"
 32             android:background="@android:color/holo_blue_dark"
 33             android:gravity="center"
 34             android:text="电池容量:4100mAh"
 35             android:textColor="#4E342E"
 36             android:textSize="30dp" />
 37 
 38         <TextView
 39             android:id="@+id/text_view3"
 40             android:layout_width="match_parent"
 41             android:layout_height="wrap_content"
 42             android:layout_marginLeft="1dp"
 43             android:layout_marginTop="1dp"
 44             android:layout_marginRight="1dp"
 45             android:layout_marginBottom="1dp"
 46             android:layout_weight="1"
 47             android:background="@android:color/holo_blue_dark"
 48             android:gravity="center"
 49             android:text="屏幕尺寸:6.5英寸"
 50             android:textColor="#4E342E"
 51             android:textSize="30dp" />
 52 
 53         <TextView
 54             android:id="@+id/text_view4"
 55             android:layout_width="match_parent"
 56             android:layout_height="wrap_content"
 57             android:layout_marginLeft="1dp"
 58             android:layout_marginTop="1dp"
 59             android:layout_marginRight="1dp"
 60             android:layout_marginBottom="1dp"
 61             android:layout_weight="1"
 62             android:background="@android:color/holo_blue_dark"
 63             android:gravity="center"
 64             android:text="屏幕色彩:10.7亿色,P3广色域"
 65             android:textColor="#4E342E"
 66             android:textSize="30dp" />
 67 
 68         <TextView
 69             android:id="@+id/text_view9"
 70             android:layout_width="match_parent"
 71             android:layout_height="wrap_content"
 72             android:layout_marginLeft="1dp"
 73             android:layout_marginTop="1dp"
 74             android:layout_marginRight="1dp"
 75             android:layout_marginBottom="1dp"
 76             android:layout_weight="1"
 77             android:background="@android:color/holo_blue_dark"
 78             android:gravity="center"
 79             android:text="运行内存(RAM):8GB"
 80             android:textColor="#4E342E"
 81             android:textSize="30dp" />
 82 
 83         <TextView
 84             android:id="@+id/text_view10"
 85             android:layout_width="match_parent"
 86             android:layout_height="wrap_content"
 87             android:layout_marginLeft="1dp"
 88             android:layout_marginTop="1dp"
 89             android:layout_marginRight="1dp"
 90             android:layout_marginBottom="1dp"
 91             android:layout_weight="1"
 92             android:background="@android:color/holo_blue_dark"
 93             android:gravity="center"
 94             android:text="机身内存(ROM):256GB"
 95             android:textColor="#4E342E"
 96             android:textSize="30dp" />
 97 
 98         <TextView
 99             android:id="@+id/text_view11"
100             android:layout_width="match_parent"
101             android:layout_height="wrap_content"
102             android:layout_marginLeft="1dp"
103             android:layout_marginTop="1dp"
104             android:layout_marginRight="1dp"
105             android:layout_marginBottom="1dp"
106             android:layout_weight="1"
107             android:background="@android:color/holo_blue_dark"
108             android:gravity="center"
109             android:text="CPU型号:骁龙888 4G"
110             android:textColor="#4E342E"
111             android:textSize="30dp" />
112     </LinearLayout>
113 </LinearLayout>

苹果和小米的类似

然后我们需要在RecycleAdapterDome.java文件的onBindViewHolder函数中,给holder.itemView添加监听点击的操作,这样我们就可以实现点击华为的任一区域即可跳转到详细信息的功能。

为了判断我们点击的是华为,苹果还是小米,我们这里需要引入一个判断的逻辑

 1 if(holder.textView1.getText() == "品牌:华为") 

我这里是用品牌的名字来进行判断

然后我们为了跳转到新的activity,需要创建一个Intent类的对象intent,Intent()的第一个参数是context,即在当前的activity中,第二个参数就是我们要跳转的activity的名字,然后用startActivity()函数来启动新的activity,并进行跳转

 1 holder.itemView.setOnClickListener(new View.OnClickListener() {
 2             @Override
 3             public void onClick(View v) {
 4                 if(holder.textView1.getText() == "品牌:华为"){
 5                     Intent intent=new Intent(context,MainActivity4.class);
 6                     context.startActivity(intent);
 7                 }
 8                 if(holder.textView1.getText() == "品牌:苹果"){
 9                     Intent intent=new Intent(context,MainActivity5.class);
10                     context.startActivity(intent);
11                 }
12                 if(holder.textView1.getText() == "品牌:小米"){
13                     Intent intent=new Intent(context,MainActivity6.class);
14                     context.startActivity(intent);
15                 }
16 
17             }
18         });

最后实现功能

 

点击华为区域之后跳转到华为详细的信息

 

苹果和小米类似

 

 

 

 

 

 

点击返回键可以返回到recycleView界面,实现功能

 

posted @ 2021-10-23 20:39  Nanne1ess  阅读(133)  评论(0编辑  收藏  举报