仿知乎日报(3)

    xiaoxiao2021-03-25  99

    MainActivity分析

    1、结构

    2、界面分析

    首先第一张图片是主页面,是一个Fragment。第二张图片是左侧滑菜单,是一个ListView。整体界面是使用MaterialUI中的DrawableLayout布局。关于Drawable的使用可以看一下笔者前面的Blog。

    3、代码

    activity_main.xml

    <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include layout="@layout/title_bar" /> <FrameLayout android:id="@+id/fl_main" android:layout_width="match_parent" android:layout_height="match_parent"></FrameLayout> </LinearLayout> </FrameLayout> <ListView android:id="@+id/list_view_menu" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" android:background="#ffffff" android:divider="#ffffff"></ListView> </android.support.v4.widget.DrawerLayout>

    4、代码分析

    最外层框架使用DrawableLayout,接着主界面使用一个FrameLayout用来切换不同的主题,左边菜单栏使用一个ListView,需要注意的是要在ListView中添加 android:layout_gravity=”start” 这个属性,否则就没有侧滑的效果,其中的start是根据系统语言确定的,按照一般语言从左往右的顺序,start就是添加左侧滑菜单,end就是添加右侧滑菜单。

    转载请注明原文地址: https://ju.6miu.com/read-24455.html

    最新回复(0)