Android(2)-----Fragment //(第七周后的知识)

1、Fragment
android.app.Fragment版本://v4版本是为了由3.0向下兼容到1.6,
改那个Fragment文件里的import android.support.v4.app.Fragment;
换成 import android.app.Fragment;
!!!!!!!!!!!!!

A、首先通过package的new一个Fragment,将下面两个打钩的去掉
android:orientation="vertical" //垂直居中
android:orientation="horizontal"  //水平居中

B、修改app的版本,和Fragment导包的代码

    compile 'com.android.support:support-v4:24.0.0'
//import android.support.v4.app.Fragment;
import android.app.Fragment;

C、在Activity 里使用,使用<fragment>标签,由name属性指定相关fragment, 注:要给一个ID

    <fragment
        android:id="@+id/title_fragment"
        android:name="com.gdgm.lemon.chapter_fragment.fragment.TitleFragment"
        android:layout_width="match_parent"
        android:layout_height="50dp">
    </fragment>

   新版本

    compile 'com.android.support:support-v4:26.0.0-alpha1'
    //compile 'com.android.support:support-v4:28.+'
//compile 'com.android.support:support-v4:26.0.0-alpha1' //这个版本也可以

 

 

相关博客 http://www.cnblogs.com/mengdd/archive/2013/01/08/2851368.html


 android studio导入support -v4 包的方法:

1.进入 file-project structure

2.左边选择app

3.右边选择dependencies

4.左下角可以看到一个加号,点击选择Library dependency就可以看到可以导入的jar包,选择support-v4导入即可

或者:

1.直接到APP

 

转载于:https://www.cnblogs.com/Lemonades/p/10711685.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值