2016-09-07 4 views
0

das ist mein activity_main.xmlwie eine lineare Anordnung des activity_main.xml in einem Fragment zugreifen

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/banner_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/contact_card_line_color" 
     android:gravity="center_horizontal" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/no_internet_connection" 
      android:textColor="@color/contact_card_initial_color" 
      android:textSize="@dimen/banner_text_size" /> 
    </LinearLayout> 

    <FrameLayout 
     android:id="@+id/fragment_holder" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/banner_layout"> 

    </FrameLayout> 


    </RelativeLayout> 

In meiner Haupttätigkeit, ich

setContentView(R.layout.activity_launch_view); 

    fragment.setArguments(getIntent().getExtras()); 
      getFragmentManager().beginTransaction().replace(R.id.fragment_holder, fragment).commit(); 

In meinem Fragment,

1) konnte nicht die no Internet-Verbindung Text standardmäßig 2) Ich kann auf sie zugreifen, keine Laufzeitfehler, konnte aber den Text nicht sehen.

+0

Der Grund ist, dass Sie die Textview vor framelayout platziert, so dass die framelayout den dieses Problem Ort Textview nach dem Frame-Layout textView.To lösen verbirgt. – Vishwa

+0

verwenden Sie Schnittstelle für jedes Ereignis für lineares Layout aus Fragment –

Antwort

0

Da es sich um ein relatives Layout handelt, überschneidet sich Ihr übergeordnetes Framelayout mit Ihrer Textansicht und Sie müssen es entweder in linearlayout ändern oder das layout_below-Tag in Ihrem Bannerlayout verwenden.

0

Mit diesem Code

<?xml version="1.0" encoding="utf-8"?> 
     <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:id="@+id/banner_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/contact_card_line_color" 
      android:gravity="center_horizontal" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/no_internet_connection" 
       android:textColor="@color/contact_card_initial_color" 
       android:textSize="@dimen/banner_text_size" /> 
     </LinearLayout> 

     <FrameLayout 
      android:id="@+id/fragment_holder" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/banner_layout"> 

     </FrameLayout> 


     </LinearLayout> 
Verwandte Themen