2017-04-16 53 views
1

1-我有具有2的EditText和1個按鈕(下面的代碼是)Android Studio中誤差在片段添加的ImageView當

<android.support.constraint.ConstraintLayout                      xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.junior_yao.fragmentfrombeginning.Top_Fragment" 
    tools:layout_editor_absoluteY="81dp" 
    tools:layout_editor_absoluteX="0dp"> 

    <EditText 
    android:id="@+id/editText1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:hint="information" 
    android:inputType="text|textShortMessage" 
    android:layout_marginRight="8dp" 
    app:layout_constraintRight_toRightOf="parent" 
    android:layout_marginLeft="8dp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginTop="16dp" 
    app:layout_constraintHorizontal_bias="0.503" /> 

    <EditText 
    android:id="@+id/editText2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:hint="information" 
    android:inputType="textPersonName" 
    android:layout_marginRight="8dp" 
    app:layout_constraintRight_toRightOf="@+id/editText1" 
    android:layout_marginLeft="0dp" 
    app:layout_constraintLeft_toLeftOf="@+id/editText1" 
    android:layout_marginTop="23dp" 
    app:layout_constraintTop_toBottomOf="@+id/editText1" 
    app:layout_constraintHorizontal_bias="0.0" /> 

    <Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Send Info" 
    android:layout_marginRight="8dp" 
    app:layout_constraintRight_toRightOf="@+id/editText1" 
    android:layout_marginLeft="8dp" 
    app:layout_constraintLeft_toLeftOf="@+id/editText1" 
    android:layout_marginTop="32dp" 
    app:layout_constraintTop_toBottomOf="@+id/editText2" 
    app:layout_constraintHorizontal_bias="0.495" /> 

</android.support.constraint.ConstraintLayout> 

2-片段我有具有一個圖像查看和2另一片段TextView的

<android.support.constraint.ConstraintLayout   xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.junior_yao.fragmentfrombeginning.Down_Fragment" 
> 

    <ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/androidtest" 
    tools:layout_constraintTop_creator="1" 
    tools:layout_constraintLeft_creator="1" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginLeft="0dp" 
    android:layout_marginTop="0dp" 
    android:id="@+id/imageView" /> 

    <TextView 
    android:id="@+id/textView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Text2" 
    android:textSize="25dp" 
    android:textColor="#7FFF00" 
    tools:layout_constraintRight_creator="1" 
    tools:layout_constraintBottom_creator="1" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    tools:layout_constraintLeft_creator="1" 
    android:layout_marginBottom="30dp" 
    app:layout_constraintLeft_toLeftOf="parent" /> 

    <TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Text1" 
    android:textSize="25dp" 
    android:textColor="#7FFF00" 
    android:layout_marginRight="8dp" 
    app:layout_constraintRight_toRightOf="parent" 
    android:layout_marginLeft="8dp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    android:layout_marginTop="44dp" /> 
</android.support.constraint.ConstraintLayout> 

在第三部分我想補充的2段在主活動佈局
3 - 如果我只添加第一個片段(我沒有錯誤)

4 - 這裏的問題

如果我添加第二個片段的應用程序無法啓動,請幫我弄明白

 <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res  /android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
    tools:context="com.example.junior_yao.fragmentfrombeginning.MainActivity"> 

    <fragment 
    android:id="@+id/fragment" 
     android:name="com.example.junior_yao.fragmentfrombeginning.Top_Fragment" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentStart="true" 
    /> 

    <fragment 
    android:id="@+id/fragment12" 
     android:name="com.example.junior_yao.fragmentfrombeginning.Down_Fragment" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentStart="true" 

     /> 


    </RelativeLayout> 

回答

0

您需要添加更多的信息,以便您能有所幫助,在Java代碼片段被調用和創建以及logcat以及幫助解決問題,XML設計代碼沒有幫助。

+0

好對不起這裏的Java代碼是第一個片段的java –

0

這裏爲第1片段java代碼

 package com.example.junior_yao.fragmentfrombeginning; 


     import android.os.Bundle; 
     import android.support.annotation.Nullable; 
     import android.support.v4.app.Fragment; 
     import android.view.LayoutInflater; 
     import android.view.View; 
     import android.view.ViewGroup; 


     public class Top_Fragment extends Fragment { 



     public Top_Fragment() { 
     } 


     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

     return inflater.inflate(R.layout.fragment_top, container, false); 
} 

     @Override 
     public void onActivityCreated(@Nullable Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 
      } 
     } 

的第二片段

  package com.example.junior_yao.fragmentfrombeginning; 


      import android.os.Bundle; 
      import android.support.annotation.Nullable; 
     import android.support.v4.app.Fragment; 
     import android.view.LayoutInflater; 
      import android.view.View; 
      import android.view.ViewGroup; 

      public class Down_Fragment extends Fragment { 


      public Down_Fragment() { 

        } 


       @Override 
      public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
        // Inflate the layout for this fragment 
       return inflater.inflate(R.layout.fragment_down, container, false); 
} 

       @Override 
        public void onActivityCreated(@Nullable Bundle savedInstanceState) { 
       super.onActivityCreated(savedInstanceState); 
      } 
      } 

現在主要活動的Java代碼

 package com.example.junior_yao.fragmentfrombeginning; 

     import android.support.v7.app.AppCompatActivity; 
     import android.os.Bundle; 

     public class MainActivity extends AppCompatActivity { 

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