类微信界面

设计目标:

设计一个包含4个tab的类微信界面,通过fragment以及activity等工具来实现其功能。

功能说明:

完成类微信界面的框架设计,后续再完善其功能。

分为三部分:fragment,layout,mainactivity

代码展示:

bottom.xml界面

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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:gravity="center"
            android:text="微信"
            android:textColor="#000000"
            android:textSize="25sp" />

    </LinearLayout>

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


        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:gravity="center"
            android:text="通讯录"
            android:textColor="#000000"
            android:textSize="25sp" />

    </LinearLayout>

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

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:gravity="center"
            android:text="发现"
            android:textColor="#000000"
            android:textSize="25sp" />
    </LinearLayout>

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

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:gravity="center"
            android:text="我"
            android:textColor="#000000"
            android:textSize="25sp" />

    </LinearLayout>
</LinearLayout>

其中的一个tab01.xml

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="这是微信聊天界面"
    android:textSize="35sp" />
 

top.xml

 <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="55dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="WeChat"
        android:textColor="@color/white"
        android:textSize="30sp" />
</LinearLayout>

 用activitymain.xml将top和bottom进行连接_

 <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="55dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="WeChat"
        android:textColor="@color/white"
        android:textSize="30sp" />
</LinearLayout>

其中一个fragment1

public class Fragment1 extends Fragment{
    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.tab01, container,false);
    }
}

最后写mainactivity.java

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Fragment Fragment1,Fragment2,Fragment3,Fragment4;
    private LinearLayout linearlayout1,linearlayout2,linearlayout3,linearlayout4;
    private FragmentManager manager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Fragment1=new Fragment1();
        Fragment2=new Fragment2();
        Fragment3=new Fragment3();
        Fragment4=new Fragment4();
        manager=getSupportFragmentManager();
        FragmentTransaction transaction=manager.beginTransaction()
                .add(R.id.id_content,Fragment1)
                .add(R.id.id_content,Fragment2)
                .add(R.id.id_content,Fragment3)
                .add(R.id.id_content,Fragment4)
                ;
        transaction.commit();
        linearlayout1=findViewById(R.id.linearlayout1);
        linearlayout2=findViewById(R.id.linearlayout1);
        linearlayout3=findViewById(R.id.linearlayout1);
        linearlayout4=findViewById(R.id.linearlayout1);
        linearlayout1.setOnClickListener(this);
        linearlayout2.setOnClickListener(this);
        linearlayout3.setOnClickListener(this);
        linearlayout4.setOnClickListener(this);
    }

    private void select(int i){
        FragmentTransaction transaction=manager.beginTransaction();
        transaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.slide_out_right);
        switch (i){
            case 1:
                transaction.replace(R.id.id_tab_weixin,Fragment1).commit();
                break;
            case 2:
                transaction.replace(R.id.id_tab_friend,Fragment2).commit();
                break;
            case 3:
                transaction.replace(R.id.id_tab_tongxunlu,Fragment3).commit();
                break;
            case 4:
                transaction.replace(R.id.id_tab_setting,Fragment4).commit();
                break;


        }

    }
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.id_tab_weixin:
                select(1);
                break;
            case R.id.id_tab_friend:
                select(2);
                break;
            case R.id.id_tab_tongxunlu:
                select(3);
                break;
            case R.id.id_tab_setting:
                select(4);
                break;

        }

    }

}

 运行结果:

 

 

源码仓库地址:MyWeChat: 11111111111111

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值