安卓开发:门户设计与开发

1.作业目标

设计一个app的门户框架,需要实现3-4个tab切换效果;本功能要求需要的技术为:activity、xml、fragment,且在任一tab页中实现列表效果;本功能的实现需要使用recycleview。

2.技术说明

制作顶部页面,中心显示“微信”字样,白底黑字

 效果

制作底部按钮页面,分成四个按钮“消息”“联系人”“发现”“我的”

效果:

组合上两个页面形成初始页面

代码如下:

<?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/content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

    </FrameLayout>

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

</LinearLayout>

效果:

设置Fragment的xml文件的布局,gravity="center",文字居中,layout_gravity="center",使TextView居中。

效果:

初始化:将多个fragment添加入mainactivity.java

通过点击实现目标界面

    public void onClick(View view) {//view

        fragmenthide();

        if(view.getId()==R.id.LinearLayout1) fragmentshow(fragment1);
        if(view.getId()==R.id.LinearLayout2) fragmentshow(fragment2);
        if(view.getId()==R.id.LinearLayout3) fragmentshow(fragment3);
        if(view.getId()==R.id.LinearLayout4) fragmentshow(fragment4);

    }

    private void fragmentshow(Fragment fragment) {
        FragmentTransaction transaction=fm.beginTransaction()
                .show(fragment);
        transaction.commit();
    }
}

在tab1页面实现列表效果:

在tab1.xml中添加recycleview,并设置间距

创建item.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="wrap_content">

    <TextView
        android:id="@+id/textView10"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="TextView"
        android:textColor="#F44336"
        android:textSize="35sp" />
</LinearLayout>

创建adapter实现列表

在fragment中添加数据

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.tab1, container, false);
        recyclerView = view.findViewById(R.id.recyclerview);

        list =new ArrayList<>();

        for(int i=0;i<9;i++) {
            list.add("这是第"+i+"行数据");
        }

        adapter = new Myadapter(view.getContext(), list);

        recyclerView.setAdapter(adapter);

        LinearLayoutManager manager = new LinearLayoutManager(view.getContext());
        manager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.setLayoutManager(manager);
        return view;
    }

代码库地址:sommo/as test

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值