Android开发之类微信界面设计

本文详细介绍了如何使用Android Studio进行Android应用开发,通过创建布局文件(top.xml和bottom.xml)模拟微信聊天界面的顶部和底部栏,并在activity_main.xml中整合。同时展示了如何编写Java代码来处理页面切换和按钮点击事件,实现场景间的动态切换。
摘要由CSDN通过智能技术生成

类微信界面的开发

本文以一个案例的形式,介绍了如何使用Android Studio软件来进行Android 开发。

开发环境:Android Studio

开发步骤

  • 1.编写布局文件
  • 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"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView5"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="这是微信聊天界面"
        android:textSize="30sp"
        android:textStyle="bold"/>

</LinearLayout>
var foo = 'bar';
  • 效果
    在这里插入图片描述
  • 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"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:background="@drawable/bottom_bar"
    android:baselineAligned="false"
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/tab_weixin"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:clickable="false"
            app:srcCompat="@drawable/tab_weixin_pressed" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:clickable="false"
            android:text="微信"
            android:textColor="#ffffff"
            android:textSize="20dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/tab_frd"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:clickable="false"
            app:srcCompat="@drawable/tab_find_frd_pressed" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:clickable="false"
            android:text="朋友"
            android:textColor="#ffffff"
            android:textSize="20dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/tab_contact"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:clickable="false"
            app:srcCompat="@drawable/tab_address_pressed" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:clickable="false"
            android:text="通讯录"
            android:textColor="#ffffff"
            android:textSize="20dp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/tab_setting"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical">

        <ImageButton
            android:id="@+id/imageButton4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
            android:clickable="false"
            app:srcCompat="@drawable/tab_settings_pressed" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:clickable="false"
            android:text="设置"
            android:textColor="#ffffff"
            android:textSize="20dp" />
    </LinearLayout>
</LinearLayout>
  • 效果
    在这里插入图片描述

  • 2.activity_main.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"
    android:orientation="vertical">

    <include layout="@layout/top" />

    <FrameLayout
        android:id="@+id/id_content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

    </FrameLayout>

    <include layout="@layout/bottom" />
</LinearLayout>
  • 效果
    在这里插入图片描述

  • 3.编写4个中间部分的切换页面:消息、好友、通讯录、设置界面(以tab01.xml为例)

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/textView5"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="这是微信聊天界面"
    android:textSize="30sp"
    android:textStyle="bold"/>
  • 效果
    在这里插入图片描述

2.编写java文件。在java文件中编写button的点击触发事件,用于实现不同页面之间的切换和图片之间的变换。(以selectFragment代码片段为例)

private void selectFragment(int i){                                           
    FragmentTransaction transaction = fm.beginTransaction();                  
    hideFragment(transaction);                                                
    switch(i){                                                                
        case 0:                                                               
            transaction.show(mTab01);                                         
            mImgWeixin.setImageResource(R.drawable.tab_weixin_pressed);       
            break;                                                            
        case 1:                                                               
             transaction.show(mTab02);                                        
             mImgFrd.setImageResource(R.drawable.tab_find_frd_pressed);       
             break;                                                           
        case 2:                                                               
             transaction.show(mTab03);                                        
             mImgAddress.setImageResource(R.drawable.tab_address_pressed);    
             break;                                                           
        case 3:                                                               
             transaction.show(mTab04);                                        
             mImgSettings.setImageResource(R.drawable.tab_settings_pressed);  
             break;                                                           
        default:                                                              
            break;                                                            
    }                                                                         
    transaction.commit();                                                     
}                                                                             
  • 最终效果

在这里插入图片描述

编码于此就完成了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值