【问题标题】:I can not see the app as I would like it我无法看到我想要的应用程序
【发布时间】:2018-04-28 12:52:18
【问题描述】:

我正在用片段做这个练习..我如何从我开发的代码中看到..我在 java / layout 文件夹中有两个类 fragment1 和 fragment2。然后是接口的两个.xml文件..现在很难理解为什么这不能正常工作..我必须得到的是:屏幕必须显示两个部分,一个带有脚本“这是片段1”和另一边“这是片段 2”......但这不可见我什至附上了屏幕..如果你有时间和耐心,请查看你的新闻..谢谢,美好的一天:) 片段1.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

【问题讨论】:

  • 从几个应用程序清理手机后,我设法通过 Gradle Projects 安装并使用 installDebug .. 现在应用程序看起来像我想要的!谢谢大家!!

标签: java android android-layout android-fragments


【解决方案1】:

错误与代码无关,它已成功构建,尝试从设备上卸载应用程序并清理构建项目,然后再次尝试运行。应该可以的。

【讨论】:

  • 感谢您的回答 Yogesh .. 抱歉,但您建议我做的是创建一个新项目 .. 可以删除它,但从我运行应用程序的设备上什至没有显示
  • stackoverflow.com/questions/37015030/… 这可能会解决你的问题
【解决方案2】:

尝试使用 adb 安装 apk,如果失败,您将收到一条错误消息,然后您可以继续操作。

adb install my.apk

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2016-12-22
    • 2023-01-30
    • 1970-01-01
    • 2021-11-24
    相关资源
    最近更新 更多