仿美团、京东、饿了么点击左边列表 右边切换布局UI

本文介绍了一个在Android中实现类似美团、京东、饿了么的UI布局方式,通过在一个Activity中添加两个Fragment,左侧Fragment作为列表,右侧Fragment根据列表选择展示不同内容。点击左侧列表项时,通过接口回调将位置信息传递给右侧Fragment,动态更新其布局和内容。
摘要由CSDN通过智能技术生成

实现思路:一个activity中添加2个fragment,左边的frgament继承自ListFragment,右边的frgament只是做布局UI上的改变直接继承自Fragment,当点击左边列表的某一项item右边的fragment显示对应的信息

MainActivity中布局文件xml中主要是放置两个FrameLayout:

<?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="match_parent"
    android:orientation="horizontal"
    tools:context="com.example.wuke02.listfragmentdemo.MainActivity">
    <FrameLayout
        android:id="@+id/left_fragment"
        android:layout_width="80dp"
        android:layout_height="match_parent"
        android:background="@color/green">
    </FrameLayout>
    <FrameLayout
        android:id="@+id/right_fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:background="@color/blue"></FrameLayout>

</LinearLayout>

分别是给fragment分配显示空间大小。

MainActivity中需处理的逻辑是先添加左边的fragment:

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值