当前位置:首页 > 嵌入式 > 嵌入式软件
[导读] 1.Fragment是最近才更新android-support-v4.jar2.Fragment是我们在单个Activity上要切换多个UI界面,显示不同内容。模块化这些UI面板以便提供给其他Acitivity使用便利。同

 1.Fragment是最近才更新android-support-v4.jar

2.Fragment是我们在单个Activity上要切换多个UI界面,显示不同内容。模块化这些UI面板以便提供给其他Acitivity使用便利。同时我们显示的Fragment也会受到当前的这个Acitivity生命周期影响。(而平常的Fragment有其自己的生命周期).

3.创建一个Fragment和创建一个Activity很类似,继承Fragment类,重写生命周期方法,主要的不同之处就是需要重写一个onCreateView()方法来返回这个Fragment的布局。

public class MainActivity extends FragmentActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.activity_main, menu);

return true;

}

}

 

android:id="@+id/fragment1"

android:name="com.example.fragmentdemosupportall.Fragement1"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1" />

 

android:id="@+id/fragment2"

android:name="com.example.fragmentdemosupportall.Fragement2"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_weight="1" />

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭