Fragement类
package com.example.testfragement;import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;public class MyFragement extends Fragment{ @Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {//创建Fragement所展现的视图
return inflater.inflate(R.layout.example_fragment, container,false);
} @Override
public void onPause() {
// TODO Auto-generated method stub
super.onPause();
}}
R.layout.example_fragment
布局<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button android:id="@+id/btn" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="点击"/>
<TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="hello" android:textSize="100.0dip"/>
</LinearLayout>
主activity界面布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/h1"
android:layout_height="match_parent" >
<fragment android:name="com.example.testfragement.MyFragement"
android:id="@+id/viewer"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
</RelativeLayout>住activity
package com.example.testfragement;import android.os.Bundle;
import android.app.Activity;import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity { @Override
public 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;
}
}
package com.example.testfragement;import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;public class MyFragement extends Fragment{ @Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {//创建Fragement所展现的视图
return inflater.inflate(R.layout.example_fragment, container,false);
} @Override
public void onPause() {
// TODO Auto-generated method stub
super.onPause();
}}
R.layout.example_fragment
布局<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button android:id="@+id/btn" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="点击"/>
<TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="hello" android:textSize="100.0dip"/>
</LinearLayout>
主activity界面布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/h1"
android:layout_height="match_parent" >
<fragment android:name="com.example.testfragement.MyFragement"
android:id="@+id/viewer"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
</RelativeLayout>住activity
package com.example.testfragement;import android.os.Bundle;
import android.app.Activity;import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity { @Override
public 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;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货