2016-12-08 3 views
0

ボタンクリックで別のフラグメントに置き換えたいPercentRelativeLayoutを含むフラグメントがあります。ここでは、外側のフラグメントXMLここAndroid Studioは、相対レイアウトを置き換えて、フレームワークを別のフラグメントに埋め込みます。

<?xml version="1.0" encoding="utf-8"?> 

<android.support.percent.PercentRelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 


    <android.support.percent.PercentRelativeLayout 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     app:layout_widthPercent="92%" 
     app:layout_heightPercent="80%" 
     app:layout_marginTopPercent="15%"> 

     <android.support.percent.PercentRelativeLayout 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent"> 

      <TextView 
       android:layout_alignParentTop="true" 
       android:layout_alignParentLeft="true" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:clickable="true" 
       android:text="Vecka 49" 
       android:id="@+id/weekOneTextView"/> 

      <android.support.percent.PercentRelativeLayout 
       app:layout_widthPercent="100%" 
       app:layout_heightPercent="0%" 
       android:layout_below="@+id/weekOneTextView" 
       android:id="@+id/displayWeekOne"> 

      </android.support.percent.PercentRelativeLayout> 

      <TextView 
       android:layout_alignParentLeft="true" 
       app:layout_widthPercent="45%" 
       app:layout_heightPercent="5%" 
       app:layout_marginTopPercent="2%" 
       android:layout_below="@+id/displayWeekOne" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Vecka 50" 
       android:id="@+id/weekTwoTextView" 
       android:clickable="true"/> 

      <android.support.percent.PercentRelativeLayout 
       app:layout_widthPercent="100%" 
       app:layout_heightPercent="0%" 
       android:layout_below="@+id/weekTwoTextView" 
       android:id="@+id/displayWeekTwo"> 

      </android.support.percent.PercentRelativeLayout> 

      <TextView 
       android:layout_alignParentLeft="true" 
       app:layout_widthPercent="45%" 
       app:layout_heightPercent="5%" 
       app:layout_marginTopPercent="2%" 
       android:layout_below="@+id/displayWeekTwo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Vecka 51" 
       android:id="@+id/weekThreeTextView" 
       android:clickable="true"/> 

      <android.support.percent.PercentRelativeLayout 
       app:layout_widthPercent="100%" 
       app:layout_heightPercent="0%" 
       android:layout_below="@+id/weekThreeTextView" 
       android:id="@+id/displayWeekThree"> 

      </android.support.percent.PercentRelativeLayout> 

      <TextView 
       android:layout_alignParentLeft="true" 
       android:layout_below="@+id/displayWeekThree" 
       app:layout_widthPercent="45%" 
       app:layout_heightPercent="5%" 
       app:layout_marginTopPercent="2%" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Vecka 52" 
       android:id="@+id/weekFourTextView" 
       android:clickable="true"/> 

      <android.support.percent.PercentRelativeLayout 
       app:layout_widthPercent="100%" 
       app:layout_heightPercent="0%" 
       android:layout_below="@+id/weekFourTextView" 
       android:id="@+id/displayWeekFour"> 

      </android.support.percent.PercentRelativeLayout> 

     </android.support.percent.PercentRelativeLayout> 

    </android.support.percent.PercentRelativeLayout> 


</android.support.percent.PercentRelativeLayout> 

は私が断片でID displayWeekOneとPercentRelativeLayoutを交換したい

private void setOnClickListeners(){ 
    mWeekOneTextView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      DropDownWeekFragment dropDownWeekFragment = new DropDownWeekFragment(); 
      FragmentManager manager = getFragmentManager(); 
      manager.beginTransaction().add(R.id.displayWeekOne, dropDownWeekFragment).commit(); 
     } 
    }); 

ファイルのJava断片でのonClickメソッドがされている、ここでフラグメントIのためであります

<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
               xmlns:tools="http://schemas.android.com/tools" 
               android:layout_width="match_parent" 
               android:layout_height="wrap_content" 
               xmlns:app="http://schemas.android.com/apk/res-auto" 
               tools:context="layout.DropDownWeekFragment"> 

    <android.support.percent.PercentRelativeLayout 
     app:layout_widthPercent="80%" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Måndag" 
      android:id="@+id/monday" 
      app:layout_marginTopPercent="2%"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Tisdag" 
      android:id="@+id/tuesday" 
      android:layout_below="@id/monday"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/wednessday" 
      android:layout_below="@id/tuesday" 
      android:text="Onsdag"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/thursday" 
      android:layout_below="@id/wednessday" 
      android:text="Torsdag"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/friday" 
      android:layout_below="@id/thursday" 
      android:text="Fredag"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/saturday" 
      android:layout_below="@id/friday" 
      android:text="Lördag"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/sunday" 
      android:layout_below="@id/saturday" 
      android:text="Söndag"/> 

    </android.support.percent.PercentRelativeLayout> 


</android.support.percent.PercentRelativeLayout> 

と交換したいとここJavaはそのフラグメントのため

012です

私は別のフラグメントを置き換えるために)私は(置き換える使用できるドキュメントを読み込むが、私はそれが可能であればPercentRelativeLayoutを交換、または外側のフラグメントにフラグメントを追加したい

答えて

0

FragmentManager manager = getFragmentManager(); manager.beginTransaction().replace(R.id.displayWeekOne, dropDownWeekFragment).commit();

をXML

replace()を使用して、Fragmentを別のFragmentと交換し、LayoutFragmentと置き換えることができます。 テストされていません。それがうまくいくことを望みます。

関連する問題