2016-04-09 6 views
0

Ich habe ein bestimmtes Layout zu setContentView() von Activity verwendet und es funktioniert einwandfrei. Aber wenn ich das gleiche Layout in einem verwende, gibt es einen bestimmten Satz von TextView s verlieren ihren Text und ich weiß nicht warum. Die Activity und Fragment haben ähnliche Größen (ungefähr 90% der Höhe des Bildschirms, 100% der Breite). Zusätzlich - wenn ich getText() für jedes der TextView s in der Tastatur der Fragment debuggen die richtigen Buchstaben zurückgegeben werden.Verschiedene TextView Aussehen in Aktivität und Fragment

With Text - Activity No Text - Fragment

Die beiden Bilder verwendet das gleiche Layout den Inhalt anzuzeigen (was mir der Fehler führt zu glauben, nicht da ist - fühlen Sie sich frei, mich zu korrigieren), aber das Fragment wird in einigen zusätzlichen Layout enthalten um die Toolbar zu geben. Dies ist der Code XML unter:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    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" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer"/> 

</android.support.v4.widget.DrawerLayout> 

R.layout.app_bar_main:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    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" 
    android:fitsSystemWindows="true" 
    tools:context="com.apps4life.quoteunquote2.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 

    </android.support.design.widget.AppBarLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/content_frame" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
     <!-- Fragments go in here --> 
    </RelativeLayout> 

</android.support.design.widget.CoordinatorLayout> 

Antwort

0

So war das Problem viel einfacher. Dieser Code war in sowohl die Activity und die Fragment:

float keyWidth = keysArray[0].getWidth(); 
for(int a = 0; a < 27; a++){ 
    keysArray[a].setTextSize(TypedValue.COMPLEX_UNIT_PX, keyWidth/2); 
} 

aber es war in OnWindowFocusChanged() im Activity und in OnCreateView() im Fragment. Dies bedeutet, dass für die Activity die keyWidth eine geeignete Größe war, während für die Fragment es 0 zu einer Textgröße von 0 führte.

Verwandte Themen