【移動應用開發(fā)技術】Adroid中Fragment的簡單使用_第1頁
【移動應用開發(fā)技術】Adroid中Fragment的簡單使用_第2頁
【移動應用開發(fā)技術】Adroid中Fragment的簡單使用_第3頁
全文預覽已結束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

【移動應用開發(fā)技術】Adroid中Fragment的簡單使用

下面四個步驟就能創(chuàng)建一個簡單的fragment1.擴展Fragmentclass2.在XML或Java中提供顯示3.覆蓋onCreateView方法4.在activity中使用Fragment如下就是簡單的顯例創(chuàng)建一個FirstActivityFragment.java文件,擴展Fragmentclasspackage

com.example.liang.login;

import

android.content.Context;

import

android.os.Bundle;

import

android.support.v4.app.Fragment;

import

android.support.v4.view.VelocityTrackerCompat;

import

android.view.LayoutInflater;

import

android.view.View;

import

android.view.ViewGroup;

import

android.widget.TextView;

import

android.widget.Toast;

/**

*

Created

by

liang

on

2016/7/15.

*/

public

class

FirstActivityFragment

extends

Fragment

{

public

FirstActivityFragment(){

}

@Override

public

View

onCreateView(LayoutInflater

inflater,

ViewGroup

container,

Bundle

savedInstanceState){

View

v

=

inflater.inflate(R.layout.fragment_first,

container,

false);

TextView

textView

=

(TextView)v.findViewById(R.id.showFirstFragmentInfo);

final

Context

context

=

this.getActivity();

textView.setOnClickListener(new

View.OnClickListener()

{

@Override

public

void

onClick(View

v)

{

Toast

hello;

hello

=

Toast.makeText(context,"hello",Toast.LENGTH_LONG);

hello.show();

}

});

return

v;

}

@Override

public

void

onCreate(

Bundle

savedInstanceState)

{

super.onCreate(savedInstanceState);

}

}為Fragment創(chuàng)建一個xml

fragment_first.xml<?xml

version="1.0"

encoding="utf-8"?>

<LinearLayout

xmlns:android="/apk/res/android"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TextView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/showFirstFragmentInfo"

android:text="this

is

a

firstFragment"/>

</LinearLayout>并在一個activityview中使用<?xml

version="1.0"

encoding="utf-8"?>

<LinearLayout

xmlns:android="/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="#33FF00">

<fragment

xmlns:android=

"/apk/res/android"

xmlns:tools="/tools"

android:id="@+id/fragment"

android:name="com.example.liang.login.FirstActivityFragment"

tools:layout="@la

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論