栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Android开发——app门户设计

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android开发——app门户设计

内容简介
源码地址:Android开发: 本人开发学习Androidhttps://gitee.com/kyrieIrving1/android-development
1.实现APP门户界面框架设计,至少包含4个tab页,能实现tab页之间的点击切换;
2.使用布局(layouts)和分段(fragment),对控件进行点击监听
3.使用git将项目传至gitee。

UI设计

以手机微信主界面为例:
  应将主界面分为三个版块,top,content,bottom;

top
  在top版块应该展示出该主界面的标题,即wechat,在AS中,可在layout使用textview部件居中展示该文字效果。

content
  在该板块,应该能够根据底部功能栏的切换而随之切换。因此,在AS中,可以使用frameLayout实现该功能,在frameLayout中包含五个fragment部件对应五个功能栏即可。

bottom
  在bottom版块中,进一步分析应将其水平划分为五个LinearLayout,在每一个LinearLayout中应该再垂直划分为两个LinearLayout

实验过程
1、bottom.xml




    

        

        
    

    

        

        
    

    

        

        
    

    

        

        
    
    

        

        
    

2.top.xml




    

3.activity_main.xml




    

    

    

    

4.内容分段fragement.xml

界面中间显示内容,有五个主界面所以要有五个xml分别对应。五个xml代码基本一样只需要修改文本内容即可,这儿就只展示了第一个资讯界面的fragment_news.xml。



    
    

5、内容分段对应java文件
仅展示其中一个java文件,其余四个文件都类似

package com.example.mywechat01;

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

import android.app.Fragment;

public class NewsFragment extends Fragment {


    public NewsFragment() {
        // 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_news, container, false);
    }
}

6、主函数MainActivity.java

package com.example.mywechat01;

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.view.Window;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;


public class MainActivity extends AppCompatActivity implements View.onClickListener {
    private Fragment chatFragment = new ChatFragment();
    private Fragment communityFragment = new CommunityFragment();
    private Fragment meFragment = new MeFragment();
    private Fragment newsFragment = new NewsFragment();
    private Fragment recordFragment = new RecordFragment();
    private FragmentManager fragmentManager;
    private View LinearLayout1,LinearLayout2,LinearLayout3,LinearLayout4,LinearLayout5;
    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_News);
        LinearLayout2 = findViewById(R.id.LinearLayout_chat);
        LinearLayout3 = findViewById(R.id.LinearLayout_community);
        LinearLayout4 = findViewById(R.id.LinearLayout_record);
        LinearLayout5 = findViewById(R.id.LinearLayout_me);

        LinearLayout1.setonClickListener(this);
        LinearLayout2.setonClickListener(this);
        LinearLayout3.setonClickListener(this);
        LinearLayout4.setonClickListener(this);
        LinearLayout5.setonClickListener(this);
        initFragment();
        showFragment(0);

    }

    private void initFragment(){
        fragmentManager = getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.content,newsFragment);
        transaction.add(R.id.content,chatFragment);
        transaction.add(R.id.content,communityFragment);
        transaction.add(R.id.content,recordFragment);
        transaction.add(R.id.content,meFragment);
        transaction.commit();
    }

    public void hideFragment(FragmentTransaction transaction){
        transaction.hide(newsFragment);
        transaction.hide(chatFragment);
        transaction.hide(communityFragment);
        transaction.hide(recordFragment);
        transaction.hide(meFragment);
    }



    private void showFragment(int i){
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        hideFragment(transaction);
        switch (i){
            case 0:
                transaction.show(newsFragment);
                LinearLayout1.setBackgroundColor(Color.rgb(255,0,0));
                LinearLayout2.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout3.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout4.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout5.setBackgroundColor(Color.rgb(0,0,0));
                break;
            case 1:
                transaction.show(chatFragment);
                LinearLayout1.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout2.setBackgroundColor(Color.rgb(255,0,0));
                LinearLayout3.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout4.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout5.setBackgroundColor(Color.rgb(0,0,0));
                break;
            case 2:
                transaction.show(communityFragment);
                LinearLayout1.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout2.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout3.setBackgroundColor(Color.rgb(255,0,0));
                LinearLayout4.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout5.setBackgroundColor(Color.rgb(0,0,0));
                break;
            case 3:
                transaction.show(recordFragment);
                LinearLayout1.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout2.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout3.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout4.setBackgroundColor(Color.rgb(255,0,0));
                LinearLayout5.setBackgroundColor(Color.rgb(0,0,0));

                break;
            case 4:
                transaction.show(meFragment);
                LinearLayout1.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout2.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout3.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout4.setBackgroundColor(Color.rgb(0,0,0));
                LinearLayout5.setBackgroundColor(Color.rgb(255,0,0));
                break;
            default:
                break;
        }
        transaction.commit();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.LinearLayout_News:
                showFragment(0);
                break;
            case R.id.LinearLayout_chat:
                showFragment(1);
                break;
            case R.id.LinearLayout_community:
                showFragment(2);
                break;
            case R.id.LinearLayout_record:
                showFragment(3);
                break;
            case R.id.LinearLayout_me:
                showFragment(4);
                break;
            default:
                break;

        }
    }
}
结果展示

 源码的代码仓库地址:

Android开发: 本人开发学习Android

 

 

 

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/306094.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号