码迷,mamicode.com
首页 > 移动开发 > 详细

[2017-7-25]Android Learning Day3

时间:2017-07-25 15:39:30      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:class   parent   哈哈   name   match   继承   水题   state   and   

最近真的有点迷茫,感觉没有一个完整的教学体系很难进行下去,有的都是自己瞎捉摸,就跟以前ACM的时候一样,动不动就“这就是一道,水题暴力就行了”、“我们枚举一下所有的状态,找一下规律就行了”,mmp哟。

 

不过!!!!!!!!!!!!!!!!!!!!!!B站简直就是万能的有没有!!!!!!!!!!!!!!!!!!!!!

 

前段时间在极客学院上看到了不错的Android教学,我看了看感觉教的有点乱,但是感觉很全。But!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

果然这些网站就是为了收钱哦,不过也可以理解啦。但是还是 买不起,结果嘿嘿嘿~~~~~~~~~~~~~~~~~~~~

 

废话不多说,快记录一下今天的自学!

 

Fragment

step1:写好两个Fragment布局文件,这个和活动的布局文件好像是一样的呢

技术分享

大概就是这个样子咯

技术分享

左边一个右边一个,所以要写两个布局文件。

<!-- left_fragment.xml 左边的布局文件 -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Button" />

</LinearLayout>

<!-- right_fragment.xml 右边的布局文件 -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="#0fa4e9"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:textSize="20sp"
        android:text="This is right fragment!" />
</LinearLayout>

 step2:讲布局文件添加到主视图里哦

 1 <!-- activity_main.xml -->
 2 <?xml version="1.0" encoding="utf-8"?>
 3 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:orientation="horizontal"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent">
 7 
 8     <fragment
 9         android:id="@+id/left_fragment"
10         <!-- 这里要注意完整的包名来引入布局文件 -->
11         android:name="com.liwenchi.learnfragment.LeftFragment"
12         android:layout_width="0dp"
13         android:layout_height="match_parent"
14         android:layout_weight="1" />
15 
16     <fragment
17         android:id="@+id/right_fragment"
18         android:name="com.liwenchi.learnfragment.RightFragment"
19         android:layout_width="0dp"
20         android:layout_height="match_parent"
21         android:layout_weight="1" />
22 
23 </LinearLayout>

step3:新建RightFragment类和LeftFragment类并继承自Fragment

技术分享

public class LeftFragment extends android.support.v4.app.Fragment{ //选择v4下的Fragment
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.left_fragment, container, false);
        return view;
    }
}

这样就OK啦。。。。。。。。。。。。

但其实我还是不知道这两个类在什么时候被调用的。。。。。。。。。我面向对象真的好菜啊!!!!!!!!!!!!!

[2017-7-25]Android Learning Day3

标签:class   parent   哈哈   name   match   继承   水题   state   and   

原文地址:http://www.cnblogs.com/liwenchi/p/7233771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!