Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未显示预期输出的片段_Android_Android Layout_Android Intent - Fatal编程技术网

Android 未显示预期输出的片段

Android 未显示预期输出的片段,android,android-layout,android-intent,Android,Android Layout,Android Intent,我是碎片的新手,我正在努力。下面是我的代码。为了它。当我运行我的应用程序时,我没有任何错误消息,但我没有得到输出 MainActivity.java public class MainActivity extends FragmentActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(

我是碎片的新手,我正在努力。下面是我的代码。为了它。当我运行我的应用程序时,我没有任何错误消息,但我没有得到输出

MainActivity.java

public class MainActivity extends FragmentActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

}
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;
}
}
MyFragments.java

public class MainActivity extends FragmentActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

}
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>
<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>
<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:weightSum="1"
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="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5" />

<fragment
    android:id="@+id/fragment_two"
    android:name="com.benchmark.fragmentsdemo.MyFragments"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5" />

</LinearLayout>

活动\u 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="vertical" >

    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

</LinearLayout>
<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>
<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:weightSum="1"
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="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5" />

<fragment
    android:id="@+id/fragment_two"
    android:name="com.benchmark.fragmentsdemo.MyFragments"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5" />

</LinearLayout>

请任何人帮帮我试试这个:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/LinearLayout1"
       android:layout_width="fill_parent"
       android:layout_height="match_parent"
       android:orientation="vertical"
        tools:context=".MainActivity" >

您的布局未正确实施

尝试以下布局

活动\u 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="vertical" >

    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

</LinearLayout>
<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>
<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:weightSum="1"
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="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5" />

<fragment
    android:id="@+id/fragment_two"
    android:name="com.benchmark.fragmentsdemo.MyFragments"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.5" />

</LinearLayout>

父线性布局的方向是垂直的,您正在进行
片段0dp的宽度,而不是高度

嘿,看看这篇关于片段的教程,有一个逐步创建它的过程,因此它可能对你有用,也可以检查developer.android提供的

你是说你的片段没有显示?