@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
//其他几个子view的后台类格式和下相同
public class AFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,
Bundle savedInstanceState){
return inflater.inflate(R.layout.frag_a, container,false);
}
}
//main.xml
<?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="horizontal"
android:background="#C0D9D9"
><!-- 水平布局,下面fragment三个水平并排布局 -->
<fragment android:name="com.example.an_fragmenttext.AFragment"
android:id="@+id/fragment_a"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent"/>
<fragment android:name="com.example.an_fragmenttext.BFragment"
android:id="@+id/fragment_b"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent"/>
<fragment android:name="com.example.an_fragmenttext.CFragment"
android:id="@+id/fragment_c"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent"/>
</LinearLayout>
//frag_a.xml ,其他子xml格式和下相同
<?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" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AFragment" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IE匹配郭德纲广告牌提问哦【额" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AF选项" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AF按钮" />
</LinearLayout>
//文件夹如下: