Android之之listfragment的使用例子的使用例子
1、、fragment简介简介
我对fragment的理解是基于activity的,对于大多数的基本开始发时,我们最先遇到的就是用activity来开发。
简单的例子,新建一个最基本的Android空白界面,我们得到的是一个可以显示一个空白界面的app。一个activity对应着一个
layout。
但是fragment则是基于activity,突破了已经固定好的layout的限制,在原有的layout中,把布局元素作为容器,动态容纳新的
layout。
这样就等于在一个activity中可以拥有多个界面。
2、、ListFragment实例讲解实例讲解
最终效果
最终效果如上图所示
2.1、首先我们先谈一下,准备工作activity_main的布局:activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<include android:id="@+id/layout_bar" layout="@layout/layout_title"/>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
</FrameLayout>
<include layout="@layout/layout_bottom"/>
</LinearLayout>
这里的线性布局,包含了三个部分(1)layout_title(2)fragment_container(3)layout_bottom