初学Fragment

      以前自己做的应用呢,及时比较小的,然后没有现在布局需要用到,或者布局的复杂程度高。所以,现在来看看这个简单的Fragment,也就好似Activity了。其实我们要做的一些大界面都推荐用Fragment吧。其实Activity肯定没有Fragment的广泛。

      为了找到与Activity的共同点,所以,我用的是一个大的布局中,引用的两个Fragment,一个是类似于Activity中的List继承系统的ListActivity一样,继承的ListFragment,然后,其实这里我们也可以直接在布局文件里面写list也ok啦。只是,从最原生的做起,其余的,我们自己练练就熟了。

    然后呢,还有一个Fragment,就是我想要同时实现两个界面上的功能变化,所以这里还用了一个普通的布局,然后来显示我们同步listFragment的点击。

    开始的是总布局:

      

    <fragment
        android:id="@+id/fragmentone"
        android:name="com.android.fragment.Fragment_Article"
        android:layout_width="300dip"
        android:layout_height="fill_parent"
        android:layout_below="@id/layout_text"
        android:layout_centerVertical="true"
        android:layout_marginBottom="50dip"
        android:layout_marginLeft="30dip"
        android:layout_marginTop="40dip" />

    <fragment
        android:id="@+id/fragmenttwo"
        android:name="com.android.fragment.Fragment_Content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/fragmentone"
        android:layout_below="@id/layout_text"
        android:layout_marginBottom="60dip"
        android:layout_marginRight="50dip"
        android:layout_toRightOf="@id/fragmentone" />

,然后就先根据两个fragment,然后写两个小布局来作为这两个Fragment的布局内容,但是这里我的是继承ListFragment,然后在写的一个小布局,来作为ListFragment的内容:

   

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@id/text_one_item"
        android:layout_width="250dip"
        android:layout_height="60dip"
        android:layout_centerHorizontal="true"
        android:background="@drawable/tp_start_selector"
        android:ellipsize="marquee"
        android:gravity="center"
        android:marqueeRepeatLimit="marquee_forever"
        android:nextFocusRight="@id/btn_pre"
        android:singleLine="true"
        android:textSize="35dp"
        android:textStyle="bold" />

</RelativeLayout>

  然后,另外一个Fragment也如此哦!

okay,小伙伴们,在这里,我就抛了一下砖,只是为了引你那块玉哦!

一切只是为了充实自己!!stay hungry and stay foolish!!
原文地址:https://www.cnblogs.com/Catherine-Brain/p/3740958.html