简体   繁体   English

从活动加载片段时出错

[英]Error when loading fragment from activity

I am new to android studio and am having some trouble with starting a fragment from an activity. 我是android studio的新手,从活动开始播放片段时遇到了一些麻烦。 I used code from on here to display the fragment and it was working up until now. 我从这里开始使用代码来显示片段,直到现在为止,它一直在工作。 I am using a third party library called 'DecoView' which needs to extend fragment, all the code is in 'LineDetails' (its too long to add all code). 我正在使用一个名为“ DecoView”的第三方库,该库需要扩展片段,所有代码都在“ LineDetails”中(添加所有代码太长了)。 Does anyone recognise this error below? 有人在下面识别此错误吗?

Thank you in advance! 先感谢您!

LINE DETAILS XML: LINE DETAILS XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="@+id/fragment_place"
android:layout_height="match_parent">

  <android.support.v4.view.ViewPager
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />
  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_alignParentTop="true"
      android:layout_alignParentStart="true">
    <com.hookedonplay.decoviewlib.DecoView
        android:layout_width="250dp"
        android:layout_height="200dp"
        android:id="@+id/dynamicArcView"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="5dp">

    </com.hookedonplay.decoviewlib.DecoView>

    <EditText
        android:id="@+id/actual"
        android:inputType="number"
        android:layout_width="150dp"
        android:layout_height="46dp"
        android:background="@drawable/border"
        android:gravity="center"
        android:hint="Enter Actual"
        android:text=""
        android:textColor="#000000"
        android:textColorHint="#000000"
        android:textSize="15sp"
        android:layout_marginStart="26dp"
        android:layout_alignBottom="@+id/textPercentage"
        android:layout_alignStart="@+id/dynamicArcView" />

    <Button
        android:id="@+id/actual_btn"
        android:layout_width="68dp"
        android:layout_height="50dp"
        android:background="@drawable/actualbutton"
        android:shadowColor="#A8A8A8"
        android:text="+"
        android:textColor="#FFFFFF"
        android:layout_above="@+id/textViewProgress"
        android:layout_toEndOf="@+id/actual"
        android:layout_marginLeft="12dp"/>

    <TextView
        android:id="@+id/textViewProgress"
        android:layout_width="200dp"
        android:layout_height="100dp"
        android:layout_marginTop="15dp"
        android:layout_below="@+id/actual"
        android:layout_alignEnd="@+id/actual_btn"
        android:layout_marginEnd="14dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text=""
        android:textSize="40sp"
        android:id="@+id/textPercentage"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="90dp"
        />

    <TextView
        android:id="@+id/textViewLineType"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="86dp"
        android:text=""
        android:textSize="40dp"
        android:textAlignment="center"
        android:textStyle="bold"
        android:textColor="#f15623"
        android:layout_alignTop="@+id/dynamicArcView"
        android:layout_toEndOf="@+id/dynamicArcView" />
    <Button
        android:id="@+id/buttonViewDetails"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:background="@mipmap/info"
        android:layout_marginLeft="250dp"
        android:onClick="verifyButton"

        android:layout_alignParentBottom="true"
        android:layout_marginBottom="14dp" />

  </RelativeLayout>


  </RelativeLayout>
<fragment
android:id="@+id/fragment_name"
class="com.almac.tracker.LineDetails"
android:layout_width="match_parent"
android:layout_height="match_parent" />

"xmlns:android="http://schemas.android.com/apk/res/android" “ xmlns:android =” http://schemas.android.com/apk/res/android“
is missing 不见了

use below code 使用以下代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <fragment
        android:id="@+id/fragment_name"
        class="com.almac.tracker.LineDetails"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

Try adding 尝试添加

    tools:context="com.yourpackagehere.FragmentThatIsInflatingTheXml">

to your first layout, the Relative one. 到您的第一个布局,相对布局。 Pls note that you have to change "yourpackagehere" with the name of your package and "FragmentThatIsInflatingTheXml" with the name of the actual Fragment 请注意,您必须使用包名称更改“ yourpackagehere”,并使用实际片段名称更改“ FragmentThatIsInflatingTheXml”

You said that DecoView extends a fragment so it should be added like this: 您说DecoView扩展了一个片段,因此应像这样添加它:

<fragment
  android:id="@+id/fragment_id"                  
  android:name="com.hookedonplay.decoviewlib.DecoView"
  android:layout_width="match_parent"
  android:layout_height="match_parent"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM