亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android Studio實(shí)現(xiàn)仿微信APP門戶界面詳解及源碼

 更新時(shí)間:2021年10月09日 09:07:17   作者:一個(gè)喪樂的野指針  
這篇文章帶你通過Android studio來實(shí)現(xiàn)微信APP的門戶界面,主要說明框架的各部分功能與實(shí)現(xiàn)過程,下文包含了整個(gè)開發(fā)過程,以及解決問題的思路并再末尾提供了源碼鏈接

前言

你好! 本文章主要介紹如何用Android Studio制作簡(jiǎn)易的門戶界面,主要說明框架的各部分功能與實(shí)現(xiàn)過程,結(jié)尾處附有源碼。

界面分析

注:按鈕圖標(biāo)是從阿里矢量圖標(biāo)庫(kù)獲取,保存在drawable文件中調(diào)用。

https://imgconvert.csdnimg.cn/aHR0cHM6Ly9hdmF0YXIuY3Nkbi5uZXQvNy83L0IvMV9yYWxmX2h4MTYzY29tLmpwZw

首先根據(jù)我們的大致規(guī)劃布局,我們可以先建立三個(gè)核心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="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="#070707"
            android:gravity="center"
            android:text="奶茶小樣"
            android:textAppearance="@style/TextAppearance.AppCompat.Body2"
            android:textColor="#F8F5F5"
            android:textSize="26sp"
            android:textStyle="bold"
            android:typeface="monospace" />
    </LinearLayout>
</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="#0B0B0B"
    android:baselineAligned="false"
    android:gravity="center|center_horizontal">

    <LinearLayout
        android:id="@+id/bottom_zhenzhu_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center|center_horizontal"
        android:orientation="vertical">

        <ImageButton
            android:id="@+id/bottom_zhenzhu_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/black"
            android:clickable="false"
            android:contentDescription="@string/app_name"
            android:src="@drawable/zhenzhu" />
        <!--            tools:srcCompat="@drawable/Zhengzhou" />-->

        <TextView
            android:id="@+id/bottom_zhenzhu_text"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="珍珠"
            android:textColor="#FBFBFB"
            android:textSize="24sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_chadong_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageButton
            android:id="@+id/bottom_chadong_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/black"
            android:clickable="false"
            android:contentDescription="@string/app_name"
            android:src="@drawable/milktea1"
            tools:srcCompat="@drawable/milktea1" />

        <TextView
            android:id="@+id/bottom_chadong_text"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="茶凍"
            android:textColor="#FBFAFA"
            android:textSize="24sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_naigai_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageButton
            android:id="@+id/bottom_naigai_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/black"
            android:clickable="false"
            android:contentDescription="@string/app_name"
            android:src="@drawable/milktea2"
            tools:srcCompat="@drawable/milktea2" />

        <TextView
            android:id="@+id/bottom_naigai_text"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="奶蓋"
            android:textColor="#FBF8F8"
            android:textSize="24sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_buding_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageButton
            android:id="@+id/bottom_buding_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/black"
            android:clickable="false"
            android:contentDescription="@string/app_name"
            android:src="@drawable/milktea3"
            tools:srcCompat="@drawable/milktea3" />

        <TextView
            android:id="@+id/bottom_buding_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="布丁"
            android:textColor="#FAF8F8"
            android:textSize="24sp" />
    </LinearLayout>

</LinearLayout>

lactivity_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:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    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="match_parent"
        android:layout_weight="1">


    </FrameLayout>

    <include
        layout="@layout/bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

注意:在top.xml和bottom.xml文件寫好后,將其插入到lactivity_main.xml文件的頭尾位置,并在中間加入FrameLayout來設(shè)置之后的Fragment文件切換。

界面動(dòng)態(tài)實(shí)現(xiàn)代碼

目錄結(jié)構(gòu):

主要java代碼文件

MainActivity:
建立相關(guān)變量:

private Fragment zhenzhuFragment=new zhenzhuFragment();
    private Fragment naigaiFragment=new naigaiFragment();
    private Fragment budingFragment=new budingFragment();
    private Fragment chadongFragment=new chadongFragment();

    private FragmentManager fragmentManager;
    private LinearLayout mTzhenzhu,mTchadong,mTnaigai,mTbuding;
    private ImageButton mTmgZhenZhu;
    private ImageButton mTmgChaDong;
    private ImageButton mTmgNaiGai;
    private ImageButton mTmgBuDing;

    private TextView text_zhenzhu;
    private TextView text_chadong;
    private TextView text_naigai;
    private TextView text_buding;

主要函數(shù)方法:

在這里插入圖片描述

OnCreate: 利用我們?cè)赬ML文件中定義的View的id屬性來獲取相應(yīng)的View對(duì)象,并且加上View.OnClickListener接口,使下方生成的OnClick()方法自動(dòng)匹配相應(yīng),同時(shí)在此函數(shù)中我們有添加了相應(yīng)的監(jiān)聽器。
initFragment:
我們?yōu)榱藢?shí)現(xiàn)界面切換,需定義Fragment文件,因?yàn)槲覀兊霓D(zhuǎn)換界面有4種,故我們總共需要5個(gè)fragment文件。
wechatFragemt:

public class wechatFragment extends Fragment {


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

其余四個(gè)文件大致上與此文件相似,但其中的onCreateView函數(shù)應(yīng)根據(jù)我們自己配置的XML文件而有所不同,例如:
budingFragment:

public class budingFragment extends Fragment {
    public budingFragment(){

    }
    @Override
    public View onCreateView( LayoutInflater inflater,  ViewGroup container,  Bundle savedInstanceState) {
//        return super.onCreateView(inflater, container, savedInstanceState);
        return inflater.inflate(R.layout.buding_fragment_wechat,container,false);
    }
}

我們可以看到,此函數(shù)的返回值是根據(jù)XML文件而作出改變,如果忽視,界面轉(zhuǎn)換將會(huì)失敗。
initFragment函數(shù)主要作用就是向之前的lacitivity_main.xml文件中的Fragment部分添加我們要做切換的代碼。

showfagment: 我們?cè)诖撕瘮?shù)中通過調(diào)用索引值來設(shè)置相應(yīng)的界面效果代碼,例如Fragment界面展示、圖片的改變、字體的設(shè)置。(由于我選擇的按鈕圖片顏色過于鮮艷,故無法實(shí)現(xiàn)點(diǎn)擊時(shí)的亮暗轉(zhuǎn)換,為了體現(xiàn)按鈕被點(diǎn)擊,我設(shè)置了當(dāng)點(diǎn)擊按鈕時(shí)字體顏色會(huì)發(fā)生變化作為替代)

hideFragment:顧名思義,此函數(shù)是為了隱藏Fragment,配合showFragment函數(shù)只顯示我們目前需要顯示的Fragment。

onClick:前面在介紹OnCreate函數(shù)時(shí)說過,是由View.OnClickListener接口生成,設(shè)置我們的點(diǎn)擊過程,并且此函數(shù)調(diào)用showFragment,完全控制我們制作的界面轉(zhuǎn)換流程。

靜態(tài)界面實(shí)現(xiàn)

目錄結(jié)構(gòu):

在這里插入圖片描述

三個(gè)核心文件在前面已經(jīng)介紹過,在此不做過多解釋,如果不清楚可翻到上面去查看。根據(jù)上述創(chuàng)建5個(gè)Fragment文件,我們應(yīng)對(duì)應(yīng)生成5個(gè)Fragment的XML文件來設(shè)計(jì)界面效果。

fragment_wechat:
此文件是由上述的的Fragment的java文件自動(dòng)生成,故其余四個(gè)文件可參考該文件進(jìn)行配置。

<?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"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".wechatFragment">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="這是微信聊天界面"
        android:textSize="48sp" />

</LinearLayout>

在此提醒,像我前面寫的Fragment的java文件因與對(duì)應(yīng)的XML文件聯(lián)系起來,我們的XML文件也應(yīng)與Fragment的java文件聯(lián)系起來。
以buding_fragment_wechat為例:

<?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"
    android:orientation="vertical"
    tools:context=".budingFragment">
<!--    tools:context=".wechatFragment"-->


    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:text="這是布丁界面"
        android:textSize="48sp" />

</LinearLayout>

調(diào)用context屬性與其JAVA文件聯(lián)系。

總結(jié)

本文介紹了AndriodStudio制作門戶界面的大致流程以及界面切換的功能,如有錯(cuò)誤,敬請(qǐng)指正。

代碼倉(cāng)庫(kù):github

碼云鏈接:https://github.com/Haru-Malfoy/work1.git

到此這篇關(guān)于Android Studio實(shí)現(xiàn)仿微信APP門戶界面詳解及源碼的文章就介紹到這了,更多相關(guān)Android 微信界面內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論