国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面

這篇具有很好參考價值的文章主要介紹了【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Android Studio簡單還原微信ui
目標(biāo)
  實現(xiàn)3-4個tab的切換效果
技術(shù)需求
  activity, xml, fragment, recyclerview
成果展示
  其中聯(lián)系人界面通過recyclerview實現(xiàn)了可以滑動列表
【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面??【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面??【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面? ?【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面
倉庫地址
https://github.com/SmileEX/wecaht.git

實現(xiàn)過程
主要ui
  第一步我們首先把微信的ui主體做出來,即這三個部分
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面
  因為中間是動態(tài)界面我們先不用寫完,把上下兩個xml編寫完之后就可以創(chuàng)建一個mainlayout.xml將他們拼起來
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent">
 7 
 8     <include
 9         layout="@layout/top"
10         android:id="@+id/topLayout"
11         android:layout_width="match_parent"
12         android:layout_height="wrap_content"
13         app:layout_constraintTop_toTopOf="parent"
14         app:layout_constraintStart_toStartOf="parent"
15         app:layout_constraintEnd_toEndOf="parent"/>
16 
17     <androidx.fragment.app.FragmentContainerView
18         android:id="@+id/fragmentContainerView"
19         android:layout_width="0dp"
20         android:layout_height="0dp"
21         app:layout_constraintBottom_toTopOf="@+id/bottomLayout"
22         app:layout_constraintEnd_toEndOf="parent"
23         app:layout_constraintHorizontal_bias="0.496"
24         app:layout_constraintStart_toStartOf="parent"
25         app:layout_constraintTop_toBottomOf="@+id/topLayout"
26         app:layout_constraintVertical_bias="0.448" />
27 
28     <include
29         android:id="@+id/bottomLayout"
30         app:layout_constraintBottom_toBottomOf="parent"
31         app:layout_constraintEnd_toEndOf="parent"
32         app:layout_constraintStart_toStartOf="parent"
33         layout="@layout/bottom"
34         android:layout_width="0dp"
35         android:layout_height="wrap_content" />
36 
37 </androidx.constraintlayout.widget.ConstraintLayout>

  然后我們再來編寫其中的fragment,就目前學(xué)習(xí)進(jìn)度而言,只需要做到中間頁面可以互相切換fragment即可,不需要對內(nèi)容進(jìn)行細(xì)節(jié)補充

所以在編寫完一個之后另外三個直接cv即可。每一個fragment.xml對應(yīng)一個fragment.java。

  下面是一個fragment.java和fragment.xml

【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面
package com.example.test;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link Fragment1# newInstance} factory method to
 * create an instance of this fragment.
 */
public class Fragment1 extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public Fragment1() {
        // 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.fragment1, container, false);
    }
}
View Code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".Fragment1">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="這是聊天界面"
        android:textSize="35sp" />

</FrameLayout>

  現(xiàn)在我們來將其中一個fragment改進(jìn)一下來讓它有更多的細(xì)節(jié),這里我把“聯(lián)系人”界面進(jìn)行了細(xì)節(jié)擴充,在其中加入了一些小說人物的頭像以及他們的姓名,看起來就像微信里的聯(lián)系人界面

  首先在layout中在添加一個xml文件用來使用recyclerview,我將其命名為activity_recycler_view.xml,代碼如下

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

?文章來源地址http://www.zghlxwxcb.cn/news/detail-710724.html


?  目前我們已經(jīng)做出了雛形,但是每個主頁都是空白并沒有內(nèi)容,接下來將其中一個頁面填充一點細(xì)節(jié)

  為了實現(xiàn)如圖的頭像+名字的這種結(jié)構(gòu),我們還需要創(chuàng)建一個xml來簡單地編寫一個規(guī)范

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面

<?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="wrap_content"
    android:background="@android:color/darker_gray"
    android:layout_margin="8dp"
    android:orientation="horizontal">

<!-- 這個是頭像 -->
    <ImageView
        android:id="@+id/tv_img"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/tv_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="內(nèi)容"
        android:textSize="30sp" />
</LinearLayout>

  在ImageView中我們不用給出圖片的路徑,因為我們會在java文件中動態(tài)的設(shè)置他們

  接下來創(chuàng)建一個RecyclerViewAdapter.java,?在Android中,RecyclerView是一個更強大和靈活的列表視圖組件,用于顯示大量數(shù)據(jù),并支持動態(tài)添加、刪除和刷新數(shù)據(jù)。

  適配器(Adapter)負(fù)責(zé)將數(shù)據(jù)綁定到RecyclerView上。

  定義RecyclerViewAdapter

  這個類繼承自RecyclerView.Adapter,它是用來將數(shù)據(jù)源(在這里是mListmSrc)與RecyclerView控件進(jìn)行綁定的。這個構(gòu)造函數(shù)接受三個參數(shù):context(上下文對象)、src(包含圖片資源的列表)、和list(包含文本數(shù)據(jù)的列表)

1 public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.Myviewholder> {
2     private List<String> mList;
3     private List<Integer> mSrc;
4     private Context context;
5     public RecyclerViewAdapter(Context context, List<Integer> src, List<String> list) {
6         this.mSrc = src;
7         this.mList = list;
8         this.context=context;
9     }

  實現(xiàn)onCreateViewHolder方法

  onCreateViewHolder方法負(fù)責(zé)創(chuàng)建并返回新的ViewHolder對象,它通過LayoutInflater將定義在R.layout.item中的布局實例化為一個View對象,并將其傳遞給Myviewholder類的構(gòu)造函數(shù)

1    @NonNull
2     @Override
3     public Myviewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){
4         View view=(View)LayoutInflater.from(parent.getContext()).inflate(R.layout.item,parent,false);
5         Myviewholder myviewholder=new Myviewholder((view));
6         return myviewholder;
7     }

  實現(xiàn)onBindViewHolder方法:

?  onBindViewHolder方法用于將數(shù)據(jù)綁定到ViewHolder上,這里根據(jù)position參數(shù)獲取對應(yīng)位置的圖片資源和文本數(shù)據(jù),并設(shè)置到ViewHolder中的ImageViewTextView

1 @Override
2     public void onBindViewHolder(@NonNull Myviewholder holder, int position) {
3         holder.tvimg.setImageResource(mSrc.get(position));
4         holder.tvContent.setText(mList.get(position));
5         position++;
6     }

  實現(xiàn)getItemCount方法:

 getItemCount方法返回數(shù)據(jù)源的大小,告訴RecyclerView有多少個數(shù)據(jù)需要顯示

1 @Override
2     public int getItemCount() {
3         return mList.size();
4     }

  定義Myviewholder內(nèi)部類:

  這個內(nèi)部類繼承自RecyclerView.ViewHolder,它持有itemView的子視圖的引用。在構(gòu)造函數(shù)中,通過itemView.findViewById方法獲取了R.id.tv_imgR.id.tv_content對應(yīng)的ImageViewTextView對象

1 public class Myviewholder extends RecyclerView.ViewHolder{
2         TextView tvContent;
3         ImageView tvimg;
4         public Myviewholder(@NonNull View itemView) {
5             super(itemView);
6             tvimg=itemView.findViewById((R.id.tv_img));
7             tvContent=itemView.findViewById(R.id.tv_content);
8         }
9     }

  然后創(chuàng)建一個fragment來初始化一些數(shù)據(jù)并用我們上面自定義的adapter來顯示我們的列表數(shù)據(jù)

 1 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
 2         View view= inflater.inflate(R.layout.activity_recycler_view, container, false);
 3         context = view.getContext();
 4         InitData();
 5         RecyclerView recyclerView = view.findViewById(R.id.recyclerview);
 6         RecyclerViewAdapter adapter = new RecyclerViewAdapter(context, mSrc, mList);
 7         recyclerView.setAdapter(adapter);
 8         LinearLayoutManager manager = new LinearLayoutManager(context);
 9         manager.setOrientation(LinearLayoutManager.VERTICAL);
10         recyclerView.setLayoutManager(manager);
11         recyclerView.addItemDecoration(new DividerItemDecoration(context,LinearLayoutManager.VERTICAL ));
12         return view;
13     }

  最后編寫MainActivity.java來完成界面轉(zhuǎn)換,底部按鈕變化等邏輯

  1 package com.example.test;
  2 
  3 import androidx.appcompat.app.AppCompatActivity;
  4 import androidx.fragment.app.Fragment;
  5 import androidx.fragment.app.FragmentManager;
  6 
  7 import android.view.View;
  8 import android.os.Bundle;
  9 import android.widget.LinearLayout;
 10 import android.widget.ImageButton;
 11 
 12 
 13 public class MainActivity extends AppCompatActivity implements View.OnClickListener {
 14     private LinearLayout linearLayout1, linearLayout2, linearLayout3, linearLayout4;
 15     Fragment fragment1,fragment2,fragment3,fragment4;
 16     ImageButton img1, img2, img3, img4;
 17     FragmentManager manager;
 18     int transaction;
 19 
 20     @Override
 21     protected void onCreate(Bundle savedInstanceState) {
 22         super.onCreate(savedInstanceState);
 23         setContentView(R.layout.mainlayout);
 24 
 25         linearLayout1 = findViewById(R.id.chat);
 26         linearLayout2 = findViewById(R.id.people);
 27         linearLayout3 = findViewById(R.id.moment);
 28         linearLayout4 = findViewById(R.id.settings);
 29 
 30         //這些圖片參數(shù)用來實現(xiàn)被點擊是底部tab圖標(biāo)的變化
 31         img1 = findViewById(R.id.button1);
 32         img2 = findViewById(R.id.button2);
 33         img3 = findViewById(R.id.button3);
 34         img4 = findViewById(R.id.button4);
 35 
 36         manager = getSupportFragmentManager();
 37 
 38         fragment1 = new Fragment1();
 39         fragment2 = new settingFragment();
 40         fragment3 = new Fragment3();
 41         fragment4 = new Fragment4();
 42 
 43         inital();
 44         fragmentHide();
 45         showfragment(fragment1);
 46         img1.setImageResource(R.drawable.tab_weixin_pressed);
 47 
 48         linearLayout1.setOnClickListener(this);
 49         linearLayout2.setOnClickListener(this);
 50         linearLayout3.setOnClickListener(this);
 51         linearLayout4.setOnClickListener(this);
 52     }
 53 
 54     public void onClick(View view) {
 55         /*
 56             每次遇到點擊事件時,首先消除以前操作留下的fragmen和imagebutton
 57             然后在修改對應(yīng)的img和fragment
 58         */
 59         fragmentHide();
 60         if (view.getId() == R.id.chat) {
 61             showfragment(fragment1);
 62             img1.setImageResource(R.drawable.tab_weixin_pressed);
 63         } else if (view.getId() == R.id.people) {
 64             showfragment(fragment2);
 65             img2.setImageResource(R.drawable.tab_address_pressed);
 66         } else if (view.getId() == R.id.moment) {
 67             showfragment(fragment3);
 68             img3.setImageResource(R.drawable.tab_find_frd_pressed);
 69         } else if (view.getId() == R.id.settings) {
 70             showfragment(fragment4);
 71             img4.setImageResource(R.drawable.tab_settings_pressed);
 72         }
 73     }
 74 
 75     private void showfragment(Fragment fragment) {
 76         transaction=manager.beginTransaction()
 77                 .show(fragment)
 78                 .commit();
 79     }
 80 
 81     //初始化容器內(nèi)的元素
 82     public void inital(){
 83         transaction=manager.beginTransaction()
 84                 .add(R.id.fragmentContainerView,fragment1)
 85                 .add(R.id.fragmentContainerView,fragment2)
 86                 .add(R.id.fragmentContainerView,fragment3)
 87                 .add(R.id.fragmentContainerView,fragment4)
 88                 .commit();
 89     }
 90 
 91     //初始化ui顯示,每次程序啟動時自動打開第一個fragment,并且點亮第一個icon
 92     public void fragmentHide(){
 93         img1.setImageResource(R.drawable.tab_weixin_normal);
 94         img2.setImageResource(R.drawable.tab_address_normal);
 95         img3.setImageResource(R.drawable.tab_find_frd_normal);
 96         img4.setImageResource(R.drawable.tab_settings_normal);
 97         transaction=manager.beginTransaction()
 98                 .hide(fragment1)
 99                 .hide(fragment2)
100                 .hide(fragment3)
101                 .hide(fragment4)
102                 .commit();
103     }
104 }

  在這段代碼中,linearLayout1, linearLayout2, linearLayout3, linearLayout4,這些變量會檢測用戶是否點擊,一旦出現(xiàn)點擊事件,程序便會根據(jù)點擊的實際情況來改變mainlayout(onclick方法)中androidx.fragment.app.FragmentContainerView的元素,以達(dá)到界面互相切換的目的,同時imagebutton變量也會根據(jù)點擊來變化(onclick方法),當(dāng)某個tab處于激活狀態(tài)是,該tab對應(yīng)的按鈕就會自動

亮起,其他按鈕熄滅。

?

開源地址
https://github.com/SmileEX/wecaht.git

到了這里,關(guān)于【移動開發(fā)學(xué)習(xí)】 Android Studio 編寫一個簡單的微信界面的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Android studio學(xué)習(xí)感受加一個簡單的登錄注冊

    作為一名使用Android Studio的學(xué)生,我也深有同感。在我看來,Android Studio是一款非常出色的開發(fā)工具先得感覺是Android Studio+Genymotion的組合比以前好用太多了。以前我記得eclipse要加各種jar包,文件夾也混亂的很。 然后是關(guān)于Activity和布局、控件,感覺跟網(wǎng)頁前端很像,布局和控

    2024年02月02日
    瀏覽(22)
  • Android studio 編寫一個登錄頁面,并且具有注冊功能

    Android studio 編寫一個登錄頁面,并且具有注冊功能

    1、創(chuàng)建登錄界面,點擊注冊按鈕,彈出注冊窗口。 2、創(chuàng)建注冊窗口,輸入用戶名和密碼,在SQLite中存儲用戶名和密碼。 3、注冊成功,跳轉(zhuǎn)到登錄界面,進(jìn)行登錄。 4、注冊成功,把用戶名和密碼保存到SharedPreferences中,登錄時自動填充用戶名和密碼。 ??????????登錄頁

    2023年04月08日
    瀏覽(21)
  • 用Android Studio編寫一個登錄界面和注冊界面并可以跳轉(zhuǎn)

    下面是使用 Android Studio 編寫一個簡單的登錄界面和注冊界面,并實現(xiàn)跳轉(zhuǎn)的示例代碼。 首先,在 res/layout 目錄下創(chuàng)建一個名為 activity_login.xml 的布局文件,作為登錄界面的布局: 接下來,在 res/layout 目錄下創(chuàng)建一個名為 activity_register.xml 的布局文件,作為注冊界面的布局:

    2024年04月09日
    瀏覽(33)
  • Visual Studio 2019 C# 上位機入門(1):如何創(chuàng)建工程編寫一個簡單應(yīng)用

    Visual Studio 2019 C# 上位機入門(1):如何創(chuàng)建工程編寫一個簡單應(yīng)用

    Visual Studio 2019下載安裝步驟可以看:https://blog.csdn.net/weixin_44788542/article/details/114271126 這里不贅述,默認(rèn)電腦上已經(jīng)安裝好了。 1、打開安裝好的Visual Studio后,選擇創(chuàng)建新項目。 2、找到選擇C#下面的Windows 窗體應(yīng)用,然后下一步起名和文件存放位置 如果找不到Windows 窗體應(yīng)用,

    2024年02月05日
    瀏覽(27)
  • 移動應(yīng)用開發(fā)環(huán)境搭建Android Studio

    移動應(yīng)用開發(fā)環(huán)境搭建Android Studio

    記得提前開啟電腦虛擬化支持,具體方法可自行百度 查看是否啟用虛擬化 JDK安裝與卸載 由于Andriod開發(fā)使用的語言是javaKotlin,這里使用的是java語言所以需要先安裝java的開發(fā)環(huán)境 所有開發(fā) Android 應(yīng)用程序需要的工具都是開源的,并且可以從互聯(lián)網(wǎng)上下載 Android Studio 是谷歌推

    2023年04月08日
    瀏覽(35)
  • 移動開發(fā)項目 Android Studio 健康助手APP

    移動開發(fā)項目 Android Studio 健康助手APP

    健康助手系統(tǒng)是一款便捷軟件,旨在通過提供多方面的的健康便捷的管理服務(wù),讓用戶的生活更健康,更便捷。用戶可以在健康助手APP上購買不同的體檢套餐,預(yù)約醫(yī)生,使用地圖查找藥房等的位置,瀏覽網(wǎng)頁了解健康知識,傳播健康文化。 (1)為了更好地了解自己的身體

    2024年02月03日
    瀏覽(32)
  • 基于android studio開發(fā)的火車票購票系統(tǒng)app,android移動開發(fā)課設(shè),畢業(yè)設(shè)計

    基于android studio開發(fā)的火車票購票系統(tǒng)app,android移動開發(fā)課設(shè),畢業(yè)設(shè)計

    基于android studio開發(fā)實現(xiàn)火車票購票系統(tǒng)app 適用于android移動開發(fā)學(xué)習(xí)項目,課程設(shè)計,畢業(yè)設(shè)計等 開發(fā)工具:android studio 或者intellij idea專業(yè)版 操作系統(tǒng):windows10 java: JDK11 構(gòu)建工具Gradle : gradle-7.0.0 模擬器AVD:pixel 3XL API 30 具體AVD配置詳情如下 APP功能 該APP包含17個Activity,每

    2024年02月09日
    瀏覽(39)
  • Android Studio制作一個簡單的計算器APP

    Android Studio制作一個簡單的計算器APP

    雖然現(xiàn)在我們?nèi)粘I钪泻苌儆玫接嬎闫?,但是第一次嘗試在Android Studio上做一個計算器 程序設(shè)計步驟: (1)在布局文件中聲明編輯文件框EditText,按鈕Button等組件。 (2)在MainActivity中獲取組件實例。 (3)通過swtich函數(shù),判斷輸入的內(nèi)容,并進(jìn)行相應(yīng)操作,通過getText()獲

    2024年02月11日
    瀏覽(35)
  • 《Android 移動應(yīng)用基礎(chǔ)教程(Android Studio)(第2版)》【學(xué)習(xí)筆記】【2023春】【附源碼】

    《Android 移動應(yīng)用基礎(chǔ)教程(Android Studio)(第2版)》【學(xué)習(xí)筆記】【2023春】【附源碼】

    《Android 移動應(yīng)用基礎(chǔ)教程(Android Studio)(第2版)》黑馬程序員 源代碼 Android——六大基本布局總結(jié)/CSDN@小馬 同學(xué) 【Android】線性布局(LinearLayout)最全解析/CSDN@Teacher.Hu 一個不錯的計算器界面?? Android Studio App LinearLayout多層布局嵌套/CSDN@pythontojava 一個簡單的布局?? Andro

    2024年02月01日
    瀏覽(29)
  • Android Studio|使用SqLite實現(xiàn)一個簡單的登錄注冊功能

    Android Studio|使用SqLite實現(xiàn)一個簡單的登錄注冊功能

    本學(xué)期學(xué)習(xí)了Android Studio這門課程,本次使用Android Studio自帶的sqlite數(shù)據(jù)庫實現(xiàn)一個簡單的登錄注冊功能。 目錄 一、了解什么是Android Studio? 二、了解什么是sqlite? 三、創(chuàng)建項目文件 ?四、創(chuàng)建活動文件和布局文件。 五、創(chuàng)建數(shù)據(jù)庫,連接數(shù)據(jù)庫 ?六、創(chuàng)建實體類,實現(xiàn)注

    2024年02月06日
    瀏覽(49)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包