一、内容

实操实现APP门户界面框架设计,至少包含4个tab页,能实现tab页之间的点击切换

二、技术

使用布局(layouts)和分段(fragment),对控件进行点击监听

三、xml代码

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="55dp"
    android:background="@color/black">
 
    <TextView
        android:id="@ id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="55dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="应用"
        android:textColor="@color/white"
        android:textSize="30sp" />
</LinearLayout>

界面居中上方写标题,背景是黑色,字体是白色

bottom.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="100dp"
    android:background="@color/black"
 
 
    >
 
    <LinearLayout
        android:id="@ id/linearLayout1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">
 
        <ImageView
            android:id="@ id/imageView2"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/p1"
 
            />
 
        <TextView
            android:id="@ id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="微信"
            android:textColor="@color/white"
            android:textSize="24sp" />
 
    </LinearLayout>
 
    <LinearLayout
        android:id="@ id/linearLayout2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">
 
        <ImageView
            android:id="@ id/imageView3"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/p2" />
 
        <TextView
            android:id="@ id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="通讯录"
            android:textColor="@color/white"
            android:textSize="24sp" />
 
    </LinearLayout>
 
    <LinearLayout
        android:id="@ id/linearLayout3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">
 
        <ImageView
            android:id="@ id/imageView4"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/p3" />
 
        <TextView
            android:id="@ id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="发现"
            android:textColor="@color/white"
            android:textSize="24sp" />
 
    </LinearLayout>
 
    <LinearLayout
        android:id="@ id/linearLayout4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">
 
        <ImageView
            android:id="@ id/imageView"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/p4" />
 
        <TextView
            android:id="@ id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="我"
            android:textColor="@color/white"
            android:textSize="24sp" />
 
    </LinearLayout>
</LinearLayout>

界面下方分成四个模板,由图片和文字组成,正在使用的界面图标为绿色,不在使用的界面图标为黑色

fragment_config.xml/fragment_wechat/fragment_friend/fragment_contact

<?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="match_parent"
    tools:context=".Fragment_config">
 
    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="这是微信聊天界面"
        android:textSize="35sp" />
 
</LinearLayout>

显示界面中间内容

activity_main.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=".MainActivity">
 
    <include
        layout="@layout/top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
 
 
    <FrameLayout
        android:id="@ id/id_content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
 
    </FrameLayout>
 
    <include
        layout="@layout/bottom"
        android:gravity="bottom" />
 
</LinearLayout>

将top.xml和bottom.xml放在一个界面中

四、Java代码

MainActivity.java

package com.example.cyxapp;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
 
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
 
 
    private Fragment Fragment_config=new Fragment_config();
    private Fragment Fragment_contact=new Fragment_contact();
    private Fragment Fragment_wechat=new Fragment_wechat();
    private Fragment Fragment_friend=new Fragment_friend();
    private FragmentManager fragmentManager;
    private LinearLayout linearLayout1,linearLayout2,linearLayout3,linearLayout4;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        linearLayout1=findViewById(R.id.linearLayout1);
        linearLayout2=findViewById(R.id.linearLayout2);
        linearLayout3=findViewById(R.id.linearLayout3);
        linearLayout4=findViewById(R.id.linearLayout4);
 
        linearLayout1.setOnClickListener(this);
        linearLayout2.setOnClickListener(this);
        linearLayout3.setOnClickListener(this);
        linearLayout4.setOnClickListener(this);
 
        initFragment();
    }
 
    private void initFragment(){
        fragmentManager=getFragmentManager();
        FragmentTransaction transaction=fragmentManager.beginTransaction();
        transaction.add(R.id.id_content,Fragment_wechat);
        transaction.add(R.id.id_content,Fragment_contact);
        transaction.add(R.id.id_content,Fragment_config);
        transaction.add(R.id.id_content,Fragment_friend);
        transaction.commit();
    }
 
 
    private void hideFragment(FragmentTransaction transaction){
        transaction.hide(Fragment_wechat);
        transaction.hide(Fragment_contact);
        transaction.hide(Fragment_config);
        transaction.hide(Fragment_friend);
    }
    private void background(View v) {
        switch (v.getId()) {
            case R.id.linearLayout1:
                linearLayout1.setBackgroundColor(Color.parseColor("#426F42"));
                break;
            case R.id.linearLayout2:
                linearLayout2.setBackgroundColor(Color.parseColor("#426F42"));
                break;
            case R.id.linearLayout3:
                linearLayout3.setBackgroundColor(Color.parseColor("#426F42"));
                break;
            case R.id.linearLayout4:
                linearLayout4.setBackgroundColor(Color.parseColor("#426F42"));
                break;
            default:
                break;
        }
    }
 
    private void backgroundreturn(View v) {
        switch (v.getId()) {
            case R.id.linearLayout1:
                linearLayout1.setBackgroundColor(Color.parseColor("#000000"));
                break;
            case R.id.linearLayout2:
                linearLayout2.setBackgroundColor(Color.parseColor("#000000"));
                break;
            case R.id.linearLayout3:
                linearLayout3.setBackgroundColor(Color.parseColor("#000000"));
                break;
            case R.id.linearLayout4:
                linearLayout4.setBackgroundColor(Color.parseColor("#000000"));
                break;
            default:
                break;
        }
    }
 
    private void showfragmnet(int i) {
 
        FragmentTransaction transaction=fragmentManager.beginTransaction();
        hideFragment(transaction);
        switch (i){
            case 0:
                transaction.show(Fragment_wechat);
                background(linearLayout1);
                backgroundreturn(linearLayout3);
                backgroundreturn(linearLayout2);
                backgroundreturn(linearLayout4);
                break;
            case 1:
                transaction.show(Fragment_friend);
                background(linearLayout2);
                backgroundreturn(linearLayout4);
                backgroundreturn(linearLayout1);
                backgroundreturn(linearLayout3);
                break;
            case 2:
                transaction.show(Fragment_contact);
                background(linearLayout3);
                backgroundreturn(linearLayout4);
                backgroundreturn(linearLayout2);
                backgroundreturn(linearLayout1);
                break;
            case 3:
                transaction.show(Fragment_config);
                background(linearLayout4);
                backgroundreturn(linearLayout1);
                backgroundreturn(linearLayout2);
                backgroundreturn(linearLayout3);
                break;
            default:
                break;
        }
        transaction.commit();
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.linearLayout1:
                showfragmnet(0);
                break;
            case R.id.linearLayout2:
                showfragmnet(1);
                break;
            case R.id.linearLayout3:
                showfragmnet(2);
                break;
            case R.id.linearLayout4:
                showfragmnet(3);
                break;
            default:
                break;
        }
    }
 
 
 
}

initFragment函数中利用transaction来实现fragment的切换

hideFragment把没有使用的界面的fragment的内容隐藏起来

background使图标点击后变绿色

backgroundreturn让图标恢复黑色

showfragmnet显示正在使用界面的fragment的内容

onClick监听函数,监听到底是哪一个图标被击中从而显示哪一个界面的内容

Fragment_config.java

package com.example.cyxapp;
 
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
 
 
public class Fragment_config extends Fragment {
 
    public Fragment_config() {
        // Required empty public constructor
    }
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_config, container, false);
    }
}

Fragment_contact、Fragment_friend、Fragment_wechat类似

五、界面展示

代码仓库地址:cccyuxuan/cyxApp1 (github.com)

到此这篇关于AndroidStudio实现微信界面设计的文章就介绍到这了,更多相关AndroidStudio 微信 内容请搜索Devmax以前的文章或继续浏览下面的相关文章希望大家以后多多支持Devmax!

AndroidStudio实现微信界面设计的更多相关文章

  1. Swift - 自定义UIActivity分享

    UIActivity可以十分方便地将文字、图片等内容进行分享,比如分享到微信、微博、发送邮件、短信等等。下面通过继承UIActivity实现定制按钮和功能,通过调用UIActivityViewController来展示分享框。,NSURL]//新建自定义的分享对象数组acts=[WeiXinActivity(),147)!important;font-family:Consolas,UIActivityTypePrintUIActivityTypeAssignToContactUIActivityType

  2. Android studio – Faild to resolve:com.android.support:design:26.0.1错误

    我有一个错误叫:我的androidstudio版本是3.0beta1.我的gradle文件如下:我想把“设计”放到我的项目中,但我不能这样做.我该怎么做?解决方法尝试改变和或者不要更改为bulidToolsversion更改依赖项

  3. 无法在Android Studio上运行应用程序项目

    我是AndroidStudio的新手,我在Ubuntu14.04LTS(64位)上安装了它.当我在AndroidStudio中打开项目时,我的项目文件标记为红色,运行按钮旁边的调试配置按钮标有红色X,如下图所示:请告诉我如何解决这个问题.解决方法一个简单的方法:>关闭当前打开的项目以返回欢迎屏幕.>从欢迎屏幕中选择导入项目.>选择要导入的EclipseADT项目.

  4. 外部AndroidManifest.xml不会出现在项目视图窗格下

    我一直在使用AndroidStudio和Gradle开发Android项目.我的项目的AndroidManifest.xml位于外部文件夹下.我使用build.gradle文件中的以下代码指向它:一切都很好,项目编译和运行,除了在使用项目视图窗格时我无法在项目结构下找到AndroidManifest.xml文件.也许我需要在build.gradle文件中添加其他东西?解决方法首先–我没有看到任何理

  5. android-studio – 未配置Dart SDK

    Initializinggradle…

  6. 如何在Android Studio 1.0.0中更改logcat字体大小?

    我只找到了改变AndroidStudio中字体颜色的方法.解决方法Logcat只使用ConsoleFont的字体设置.要在AndroidStudio中更改此设置,请转到:Settings->Editor->Color&Fonts->ConsoleFont

  7. android-studio – 在Android Studio中放置gitIgnore文件的位置?

    我将此文件复制到AndroidStudio中的gitIgnore文件中,但是当我在gitHub上推送该项目时,我的gitnigore文件如下所示:所以,我复制到AndroidStudio的文件不在这里.问题是什么?解决方法通常在创建新项目时会为您生成gitignore文件.这是正确的.gitignore文件.这是你必须把它.

  8. android-studio – 安卓工作室更新后的问题

    解决方法我在AndroidStudio中花了很多时间来处理这个问题.看来这个问题是由用于编译项目的java版本的差异引起的.最后,在“项目结构”设置窗口中,我在SDK位置选项卡中启用了“使用嵌入式JDK(推荐)”.并快乐编译:)

  9. android – 编译项目时错误25.0.0

    我有一个项目,运行良好,直到约会.今天突然面临这些问题:我的sdk也没有25.0.0,havnt仍然下载它,而且我的编译版本是23.0.2然后你是否搜索25.0.0?编辑:我现在面临的确切问题是我正在使用在gradleforfacebook.并且在这个库中它使用25.0.0所以我该如何避免呢?

  10. 如何在Android Studio中导入自定义图标?

    我为我的Android应用程序制作了自己的图标,但我是AndroidStudio的初学者,并且它没有导入我已经存在的AndroidStudio项目.我只是使用AndroidAssetStudio中的AndroidLauncherIconGenerator,然后为您创建一个zip文件,该文件应放在您的项目res文件夹中.我基本上用新的文件夹替换旧的res文件夹,我检查了所有新图标都在他们正确的文件夹

随机推荐

  1. Flutter 网络请求框架封装详解

    这篇文章主要介绍了Flutter 网络请求框架封装详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

  2. Android单选按钮RadioButton的使用详解

    今天小编就为大家分享一篇关于Android单选按钮RadioButton的使用详解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

  3. 解决android studio 打包发现generate signed apk 消失不见问题

    这篇文章主要介绍了解决android studio 打包发现generate signed apk 消失不见问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

  4. Android 实现自定义圆形listview功能的实例代码

    这篇文章主要介绍了Android 实现自定义圆形listview功能的实例代码,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  5. 详解Android studio 动态fragment的用法

    这篇文章主要介绍了Android studio 动态fragment的用法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  6. Android用RecyclerView实现图标拖拽排序以及增删管理

    这篇文章主要介绍了Android用RecyclerView实现图标拖拽排序以及增删管理的方法,帮助大家更好的理解和学习使用Android,感兴趣的朋友可以了解下

  7. Android notifyDataSetChanged() 动态更新ListView案例详解

    这篇文章主要介绍了Android notifyDataSetChanged() 动态更新ListView案例详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下

  8. Android自定义View实现弹幕效果

    这篇文章主要为大家详细介绍了Android自定义View实现弹幕效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  9. Android自定义View实现跟随手指移动

    这篇文章主要为大家详细介绍了Android自定义View实现跟随手指移动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  10. Android实现多点触摸操作

    这篇文章主要介绍了Android实现多点触摸操作,实现图片的放大、缩小和旋转等处理,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

返回
顶部