我是碎片的新手,我正在努力工作。以下是我的代碼。爲了它。當我運行我的應用程序沒有任何錯誤消息,但我沒有收到輸出片段不顯示預期輸出
MainActivity.java
public class MainActivity extends FragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
MyFragments.java
public class MyFragments extends Fragment {
public MyFragments() {
// TODO Auto-generated constructor stub
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
return view;
}
}
fragment_one.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="TextView" />
</LinearLayout>
activity_main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_One"
android:name="com.benchmark.fragmentsdemo.MyFragments"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<fragment
android:id="@+id/fragment_two"
android:name="com.benchmark.fragmentsdemo.MyFragments"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
</LinearLayout>
請人幫助我
你的意思是你的碎片沒有顯示? – FWeigl 2013-02-28 09:00:16