欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

前言

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

界面分析

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

https://imgconvert.csdnimg.cn/aHR0cHM6Ly9hdmF0YXIuY3Nkbi5uZXQvNy83L0IvMV9yYWxmX2h4MTYzY29tLmpwZw

首先根據(jù)我們的大致規(guī)劃布局,我們可以先建立三個核心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來設置之后的Fragment文件切換。

界面動態(tài)實現(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: 利用我們在XML文件中定義的View的id屬性來獲取相應的View對象,并且加上View.OnClickListener接口,使下方生成的OnClick()方法自動匹配相應,同時在此函數(shù)中我們有添加了相應的監(jiān)聽器。
initFragment:
我們?yōu)榱藢崿F(xiàn)界面切換,需定義Fragment文件,因為我們的轉(zhuǎn)換界面有4種,故我們總共需要5個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);
    }
}

其余四個文件大致上與此文件相似,但其中的onCreateView函數(shù)應根據(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)換將會失敗。
initFragment函數(shù)主要作用就是向之前的lacitivity_main.xml文件中的Fragment部分添加我們要做切換的代碼。

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

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

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

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

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

在這里插入圖片描述

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

fragment_wechat:
此文件是由上述的的Fragment的java文件自動生成,故其余四個文件可參考該文件進行配置。

<?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文件因與對應的XML文件聯(lián)系起來,我們的XML文件也應與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制作門戶界面的大致流程以及界面切換的功能,如有錯誤,敬請指正。

代碼倉庫:github

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

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

相關(guān)文章

最新評論