私は断片とこの練習をしています..どのように私が開発したコードから参照してください..私は私の2つのクラスfragment1とfragment2、java /レイアウトフォルダ。次に、インターフェイスの2つの.xmlファイルがあります。なぜこれが適切に動作しないのか理解することは難しいです。私が取得しなければならないのは、画面にスクリプトの2つの部分が表示されている必要があります。 "これはフラグメント1 "と反対側に"これは断片2です... "しかし、これは表示されません私はさらに画面を添付..あなたは時間と忍耐があれば、あなたのニュースを見て..ありがとう、良い日:) fragment1 .java私はそれが好きだとアプリを見ることができません
package layout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.test.testfragment.R;
/**
* A simple {@link Fragment} subclass.
*/
public class fragment1 extends Fragment {
public fragment1(){
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment1,container,false);
}
}
fragment2.java
package layout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.test.testfragment.R;
/**
* A simple {@link Fragment} subclass.
*/
public class fragment2 extends Fragment {
public fragment2(){
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment2, container,false);
}
}
fragment1.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:ignore="HardcodedText">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Questo e' il fragment 1"
android:textSize="25sp"/>
</LinearLayout>
fragment2.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00FF00"
tools:ignore="HardcodedText">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Questo e' il fragment 2"
android:textSize="25sp"/>
</LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="false"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.example.test.testfragment.MainActivity">
<fragment
android:id="@+id/fragment1"
android:layout_width="0px"
android:name="layout.fragment1"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@layout/fragment1" />
<fragment
android:name="layout.fragment2"
android:id="@+id/fragment2"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
</LinearLayout>
いくつかのアプリから電話を掃除した後、私はGradle ProjectsとinstallDebugを使ってインストールしました。皆さん、ありがとうございました !! – Serra