AS-类微信界面的制作

作业目标:

做出一个类似微信的界面框架,要求点击下方四个底部部件可以进行页面之间的切换,在任一tab页中实现列表效果。

技术说明 :

activity

xml

fragment

关键代码解析:

实验思路:

该页面主要分为上中下三个部分,底部的bottom.xml和顶部的top.xml是不变的,主要是中间部分会随着用户的点击而进行切换

实验内容:

1.xml文件的编写

1.需要的图片放到drawable目录下面

2.进行top.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:background="@color/black">

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:text="微信"
        android:gravity="center"
        android:textColor="@color/white"
        android:textSize="40sp" />
</LinearLayout>
3.bottom的创建

其本质就是一个图片下面加文字,同样的创建四个,调整好布局就可以了

效果如下:

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/llayout11"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#000000"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView11"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:src="@drawable/a"/>

        <TextView
            android:id="@+id/textView11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="聊天"
            android:textColor="#ffffff"
            android:textSize="30sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llayout22"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@color/black"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView22"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:src="@drawable/b" />

        <TextView
            android:id="@+id/textView22"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="联系人"
            android:textColor="@color/white"
            android:textSize="30sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llayout33"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@color/black"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView33"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:src="@drawable/c" />

        <TextView
            android:id="@+id/textView33"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="位置"
            android:textColor="@color/white"
            android:textSize="30sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llayout44"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@color/black"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageView44"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_gravity="center"
            android:src= "@drawable/d" />

        <TextView
            android:id="@+id/textView44"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="设置"
            android:textColor="@color/white"
            android:textSize="30sp" />
    </LinearLayout>
</LinearLayout>
4.中间部分

其实中间部分就是一段文字,我们要创建四个用以切换,这里展示一个,其他三个以此类推,只有文字内容有点区别,创建四个xml文件然后进行编辑

效果如下:

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Fragment1">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="这是聊天界面"
        android:textSize="40sp" />

</FrameLayout>
5.main.xml的创建

这一部分主要是把底部和顶部以及中间放到一个界面中,显示出来

效果如下:

代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <include layout="@layout/top" ></include>

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_gravity="center">
    </FrameLayout>

    <include layout="@layout/bottom"></include>


</LinearLayout>

 2.java文件的编写

创建四个fragment

代码如下:

package com.example.myapplication;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class Fragment1 extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.tab1, container, false);
    }
}

注意这里R.layout.tab1这里,四个是不一样的,R.layout.后面的内容与你中间页面的命名有关

Mainactivity的编写
1.初始化:将fragment加入到MainActivity的布局中
public void inital() {

        FragmentTransaction ft = fm.beginTransaction()
                .add(R.id.content,fragment1)
                .add(R.id.content,fragment2)
                .add(R.id.content,fragment3)
                .add(R.id.content,fragment4);
        ft.commit();

    }
2.编写隐藏函数,编写隐藏函数的目的就是中间显示一个文字,隐藏其他三个
private void fragmenthide() {
        FragmentTransaction ft = fm.beginTransaction()
                .hide(fragment1)
                .hide(fragment2)
                .hide(fragment3)
                .hide(fragment4);
        ft.commit();
    }
3.编写show函数
 private void fragmentshow(Fragment fragment) {
        FragmentTransaction transaction = fm.beginTransaction()
                .show(fragment);
        transaction.commit();
    }
 4.onclick事件:点击切换中间界面
 @Override
    public void onClick(View view) {
        fragmenthide();
        if (view.getId()==R.id.llayout11){
            fragmentshow(fragment1);
        }else if (view.getId()==R.id.llayout22){
            fragmentshow(fragment2);
        }else if (view.getId()==R.id.llayout33){
            fragmentshow(fragment3);
        }else if(view.getId()==R.id.llayout44){
            fragmentshow(fragment4);
        }
    }

3.Recycleview的编写 

在Fragment1中修改,在微信界面显示列表

先初始化定义一些变量recyclerView,list,context, myadapter

private RecyclerView recyclerView;
private List<String> list;
private Context context;
private  myadapter myadapter;

在onCreateView()函数底下写入适配器需要的一些参数和数据:

    View view=inflater.inflate(R.layout.tab1,container,false);
        context=view.getContext();
        recyclerView=view.findViewById(R.id.tab1);
        list=new ArrayList();

        initial();
        myadapter = new MyAdapter(context,list);
        recyclerView.setAdapter(myadapter);
        LinearLayoutManager manager=new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);

        return view;

 在Fragment1写initData()来定义需要输出的文字(可自定义改成你想要的):

 private void initial() {
        list.add("算法");
        list.add("分析");
        list.add("应用");
        list.add("计算");
        list.add("网络");
        list.add("安全");
        list.add("病毒");
        list.add("防护");
        list.add("技术");
        list.add("ending~");
    }

 新建一个名叫myadapter的类来初始化定义适配器:

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;
import java.util.zip.Inflater;

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.Myholder> {

    Context context1;
    List<String> list1;
    public MyAdapter(Context context,List list) {
        context1=context;
        list1=list;
    }

    @NonNull
    @Override
    public Myholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context1).inflate(R.layout.item,parent,false);

        Myholder holder = new Myholder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull Myholder holder, int position) {
        holder.textView.setText(list1.get(position));
    }

    @Override
    public int getItemCount() {
        return list1.size();
    }

    public class Myholder extends RecyclerView.ViewHolder{
        TextView textView;
        public Myholder(@NonNull View itemView) {
            super(itemView);
            textView=itemView.findViewById(R.id.item);
        }
    }
}

写完后运行结果如下:

 

 总体效果如下:

实验心得:

如果说你得到了上面和我一样的实验结果,那么恭喜你完结撒花啦,但是如果你出现小问题的话,一定要耐心仔细地解决,代码很多,出错的可能性很大,大家一定要耐心一点。这也是我第一次利用as进行类微信的界面设计,使我对fragment,xml,layout的编写有了更加深刻的理解,难点其实就是在于怎么实现中间界面的跳转,as的提词器很好用,也鼓励了我勇敢大胆的去试错。

下面是我的源代码地址:https://gitee.com/shao-zhenfeng/as-weichat.git

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: HM-A300 微信小程序 SDK 是为了方便开发者在 HM-A300 手环上运行微信小程序而开发的一套软件开发工具包。它提供了一系列的接口和方法,使开发者能够在手环上实现微信小程序的功能和交互。 HM-A300 是一款功能强大的智能手环,具备心率监测、运动监测、睡眠监测等功能,支持与手机的蓝牙连接,并能与微信小程序进行交互。HM-A300 微信小程序 SDK 的出现,进一步拓宽了 HM-A300 的功能,使开发者能够通过编写微信小程序,为手环添加更多个性化的功能。 HM-A300 微信小程序 SDK 提供了一系列的开发工具和接口,包括蓝牙通信、设备状态获取、数据传输等功能。开发者可以通过这些接口与手环进行通信,控制手环的运行状态,读取传感器数据,发送指令等操作。同时,HM-A300 微信小程序 SDK 还提供了开发文档和示例代码,方便开发者快速上手和开发。 借助 HM-A300 微信小程序 SDK,开发者可以为手环开发日常活动监测、健康管理、消息提醒、运动计划等功能。比如,开发者可以通过手环上的传感器监测心率和运动数据,并将数据实时传输到微信小程序,用户可以通过小程序查看自己的健康状况和运动情况。同时,开发者还可以通过微信小程序发送消息提醒、设置闹钟等功能,实现个性化的定制需求。 总之,HM-A300 微信小程序 SDK 为开发者提供了丰富的开发工具和接口,使其能够在 HM-A300 手环上开发出更多个性化的功能和交互,丰富用户的使用体验。 ### 回答2: HM-A300微信小程序SDK是一个开发工具,旨在帮助开发者快速、高效地开发微信小程序。它提供了一系列接口和组件,使开发者能够方便地使用微信小程序的各种功能和特性。 HM-A300微信小程序SDK包含了丰富的API,可以让开发者实现小程序的各种功能,包括用户登录、数据读写、支付等。通过使用SDK提供的接口,开发者可以轻松地与微信服务器进行交互,并获取、处理用户的数据。 此外,HM-A300微信小程序SDK还提供了一些可复用的组件,如导航栏、菜单、按钮等,可以极大地简化开发过程。这些组件可以快速集成到小程序中,减少开发工作量,提高开发效率。 HM-A300微信小程序SDK还具备良好的文档和示例,方便开发者学习和使用。它提供了详细的API文档,包含了每个接口的详细说明、参数和返回值等。同时,SDK还提供了一些实用的示例代码,开发者可以参考这些示例来了解如何使用SDK进行开发。 总之,HM-A300微信小程序SDK是一个强大而且易于使用的工具,可以帮助开发者快速、灵活地开发微信小程序。它提供了丰富的接口和组件,方便开发者使用微信小程序的各种功能和特性,并拥有良好的文档和示例,帮助开发者快速入门和提高开发效率。 ### 回答3: hm-a300 微信小程序 SDK 是为了方便开发者在 HM-A300 智能设备上集成微信小程序而开发的软件开发工具包。通过使用该 SDK,开发者可以快速地将微信小程序运行在 HM-A300 智能设备上,实现智能设备与微信小程序的交互。 HM-A300 微信小程序 SDK 提供了丰富的功能和接口,开发者可以使用这些功能和接口来实现与智能设备相关的业务逻辑。具体来说,该 SDK 包含以下几个方面的内容: 1. 设备连接与通信:SDK 提供了设备连接与通信的接口,可以实现 HM-A300 智能设备与微信小程序之间的数据传输和双向通信,包括设备的连接、断开、发送和接收数据等功能。 2. 数据解析与处理:SDK 提供了对设备发送和接收的数据进行解析和处理的能力,开发者可以使用这些功能来处理设备返回的数据,并提取所需的信息进行相应的处理。 3. 设备控制与操作:SDK 提供了对 HM-A300 智能设备进行各种控制和操作的接口,包括对设备的打开、关闭、设置参数、查询状态等功能,方便开发者进行设备的控制和管理。 4. 视图和界面:SDK 提供了默认的视图和界面,方便开发者快速搭建和调整小程序界面,提高开发效率。 总之,HM-A300 微信小程序 SDK 提供了一套全面而且易用的工具,方便开发者在 HM-A300 智能设备上集成微信小程序,并实现各种与设备相关的功能和交互。通过使用该 SDK,开发者可以更加高效地进行智能设备开发,提升用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值