IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> Android初学三之仿微信APP实现对有recycleView的页面进行点击跳转设计 -> 正文阅读

[移动开发]Android初学三之仿微信APP实现对有recycleView的页面进行点击跳转设计

1.主要代码

改进后的界面为:

2.掌握复杂控件与adapter的使用。(请使用RecycleView进行设计)

MainActivity

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.app.Fragment;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {
??? private Fragment weixinAdventure = new weixinAdventure();
??? private Fragment weixinCommitment = new weixinCommitment();
??? private Fragment weixinForum = new weixinForum();
??? private Fragment weixinLevel = new weixinLevel();
??? private FragmentManager fragmentManager;
??? private View LinearLayout1,LinearLayout2,LinearLayout3,LinearLayout4;
??? private TextView textView1,textView2,textView3,textView4;


??? @Override
??? protected void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
??????? setContentView(R.layout.activity_main);

??????? LinearLayout1 = findViewById(R.id.LinearLayout_weixinAdventure);
??????? LinearLayout2 = findViewById(R.id.LinearLayout_weixinCommitment);
??????? LinearLayout3 = findViewById(R.id.LinearLayout_weixinForum);
??????? LinearLayout4 = findViewById(R.id.LinearLayout_weixinLevel);
??????? textView1 = findViewById(R.id.textView1);
??????? textView2 = findViewById(R.id.textView2);
??????? textView3 = findViewById(R.id.textView3);
??????? textView4 = findViewById(R.id.textView4);

??????? LinearLayout1.setOnClickListener(this);
??????? LinearLayout2.setOnClickListener(this);
??????? LinearLayout3.setOnClickListener(this);
??????? LinearLayout4.setOnClickListener(this);
??????? textView1.setOnClickListener(this);
??????? textView2.setOnClickListener(this);
??????? textView3.setOnClickListener(this);
??????? textView4.setOnClickListener(this);
??????? initFragment();
??????? showFragment(0);

??? }

??? private void initFragment(){
??????? fragmentManager = getFragmentManager();
??????? FragmentTransaction transaction = fragmentManager.beginTransaction();
??????? transaction.add(R.id.content,weixinAdventure);
??????? transaction.add(R.id.content,weixinCommitment);
??????? transaction.add(R.id.content, weixinForum);
??????? transaction.add(R.id.content, weixinLevel);
??????? transaction.commit();
??? }

??? public void hideFragment(FragmentTransaction transaction){
??????? transaction.hide(weixinAdventure);
??????? transaction.hide(weixinCommitment);
? ??????transaction.hide(weixinForum);
??????? transaction.hide(weixinLevel);
??? }



??? private void showFragment(int i){
??????? FragmentTransaction transaction = fragmentManager.beginTransaction();
??????? hideFragment(transaction);
??????? switch (i){
??????????? case 0:
??????????????? transaction.show(weixinAdventure);
??????????????? textView1.setText("冒险");
??????????????? break;
??????????? case 1:
??????????????? transaction.show(weixinCommitment);
??????????????? textView1.setText("委托");
??????? ????????break;
??????????? case 2:
??????????????? transaction.show(weixinForum);
??????????????? textView1.setText("论坛");
??????????????? break;
??????????? case 3:
??????????????? transaction.show(weixinLevel);
??????????????? textView1.setText("能力");
? ??????????????break;
??????????? default:
??????????????? break;
??????? }
??????? transaction.commit();
??? }

??? @Override
??? public void onClick(View v) {
??????? switch (v.getId()){
??????????? case R.id.LinearLayout_weixinAdventure:
??????????????? showFragment(0);
??????????????? break;
??????????? case R.id.LinearLayout_weixinCommitment:
??????????????? showFragment(1);
??????????????? break;
??????????? case R.id.LinearLayout_weixinForum:
??????????????? showFragment(2);
??????????????? break;
?? ?????????case R.id.LinearLayout_weixinLevel:
??????????????? showFragment(3);
??????????????? break;
??????????? default:
??????????????? break;

??????? }
??? }
}

item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
??? android:orientation="vertical">
?? ?<include layout="@layout/layout_sticky_header_view" />

??? <LinearLayout
??????? android:id="@+id/LinearLayoutWechatItem"
??????? android:layout_width="match_parent"
??????? android:layout_height="wrap_content"
??????? android:layout_marginBottom="5sp"
??????? android:layout_weight="1"
??????? android:background="#666699"
??????? android:gravity="center"
??????? android:orientation="horizontal"
??????? app:layout_constraintEnd_toEndOf="parent"
??????? app:layout_constraintStart_toStartOf="parent">

????? ??<LinearLayout
??????????? android:layout_width="300sp"
??????????? android:layout_height="match_parent"
??????????? android:layout_weight="1"
??????????? android:gravity="left"
??????????? android:orientation="vertical">

??????????? <TextView
????????? ??????android:id="@+id/wechat_name_text"
??????????????? android:layout_width="match_parent"
??????????????? android:layout_height="match_parent"
??????????????? android:layout_weight="1"
??????????????? android:text="wechatName"
??????????????? android:textSize="25sp" />

??????????? <TextView
??????????????? android:id="@+id/wechat_content_validity"
??????????????? android:layout_width="match_parent"
??????????????? android:layout_height="match_parent"
??????????????? android:layout_weight="1"
?????????? ?????android:text="content validity"
??????????????? android:textSize="16sp" />
??????? </LinearLayout>

??????? <TextView
??????????? android:id="@+id/wechat_text_time"
??????????? android:layout_width="60sp"
??????????? android:layout_height="match_parent"
??????????? android:layout_weight="1"
??????????? android:gravity="center"
??????????? android:textSize="16sp" />

??? </LinearLayout>

</LinearLayout>

activity_contacts_details.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".ContactsDetails">


    <TextView
        android:id="@+id/wechat_contacts_details"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="委托详情"
        android:textSize="36sp" />

</LinearLayout>

ContactsDetails

package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class ContactsDetails extends AppCompatActivity {

    private TextView wechat_contacts_details;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contacts_details);
        Log.d("life","activity_contacts_details is creating...");
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        int age = intent.getIntExtra("age", 18);
        Log.d("life","name:"+name+",age:"+age);
        wechat_contacts_details = findViewById(R.id.wechat_contacts_details);
        wechat_contacts_details.setText("委托完成后记得领取药剂哦~");

    }
    @Override
    protected void onStart() {
        super.onStart();
        Log.d("life","activity_contacts_details is starting...");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("life","activity_contacts_details is stopping...");
    }
    @Override
    public void finish() {
        super.finish();
        Log.d("life","activity_contacts_details is finishing...");
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("life","activity_contacts_details is destroying...");
    }

    @Override
    public void finishActivity(int requestCode) {
        super.finishActivity(requestCode);
        Log.d("life","activity_contacts_details is finishActivity...");
    }
}

代码仓库:https://github.com/aedela/My_Application3

  1. 结果截图

??

?

?

?

?

?

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-10-27 12:56:47  更:2021-10-27 12:58:34 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 1:14:25-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码