- 绑定照片到RecyclerView中 —— OK 但是非常卡,基本不能用
- Fragment 动态调用 ——OK
- 布局的嵌套,底部按钮四个按钮的布局文件设计 ,线性布局的权重设置 —— OK
1.Fragment将每一个视图部分(Fragment)的视图设置(Fragment layout)和程序编写(XXFragment.class)相分开 ,
提高了代码的可读性,复用性和维护性
2.使用RelativeLayout + LinearLayout 嵌套完成四个按钮底部均匀放置,
使用RelativeLayout完成放置底部操作
android:layout_alignParentBottom="true"
设置权重,完成四个按钮的均匀对齐
android:layout_weight="1"
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageButton android:id="@+id/ib_bottombar_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@android:drawable/ic_menu_add" android:scaleType="center" /> <ImageButton android:id="@+id/ib_bottombar_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@android:drawable/ic_menu_edit" android:scaleType="center" /> <ImageButton android:id="@+id/ib_bottombar_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@android:drawable/ic_menu_delete" android:scaleType="center" /> <ImageButton android:id="@+id/ib_bottombar_more" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@android:drawable/ic_menu_more" android:scaleType="center" /> </LinearLayout> </RelativeLayout>
3.可以使用 include完成布局嵌套,使得主布局activity_main显得简洁
以下的主布局由三个部分构成
(1)标题的fragment (包含一个左上角的menu,一个居中显示的text标题)
(2)(include) 底端四个按钮的布局
(3)FramLayout 四个按钮分别对应的四个界面fragment 切换显示
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="edu.dhu.lichong.fragmentdemo.MainActivity"> <fragment android:id="@+id/id_fragment_title" android:name="edu.dhu.lichong.fragmentdemo.TitleFragment" android:layout_width="match_parent" android:layout_height="45dp"/> <include android:id="@+id/id_ly_bottombar" layout="@layout/bottombar" android:layout_width="match_parent" android:layout_height="55dp" android:layout_alignParentBottom="true" /> <FrameLayout android:id="@+id/fragment_content" android:layout_above="@+id/id_ly_bottombar" android:layout_below="@+id/id_fragment_title" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> </RelativeLayout>