我无法看到我想要的应用程序

时间:2017-11-15 10:30:19

标签: java android android-layout android-fragments

我正在使用片段进行此练习..我如何从我开发的代码中看到..我在java / layout文件夹中有我的两个类fragment1和fragment2。然后是接口的两个.xml文件..现在很难理解为什么这不能正常工作..我必须得到的是:屏幕必须显示两个部分,一个是脚本"这个是片段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>

activity_main (Design)

Error

2 个答案:

答案 0 :(得分:0)

错误不是代码,它是成功构建的,尝试从设备中取消应用程序并清理构建项目然后再次尝试运行。这应该有用。

答案 1 :(得分:0)

尝试使用adb安装apk,如果失败则会收到错误消息,然后您可以继续处理。

adb install my.apk
相关问题