2017-09-19 50 views
1

構建應用程序後,我無法看到任何內容(文字瀏覽)。 只有背景圖像顯示,沒有別的。嘗試了一切,但仍然沒有顯示文本。 在scrollview下我做了一個線性佈局,在那之下還有幾個其他的文字瀏覽。但是當我構建應用程序時,它們都沒有顯示出來。 我如何使scrollview下的所有內容都可見? 這裏是我的代碼:在滾動視圖內無法查看任何內容(textviews)

`

<ScrollView 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:background="@drawable/blck" 
    android:weightSum="1" 

    tools:context="com.gnulinuxusersgroup.nitdgp.glug.faqs" 
    app:layout_collapseParallaxMultiplier="1.0"> 

    <!-- TODO: Update blank fragment layout --> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 



    <TextView 
      android:layout_width="match_parent" 
      android:layout_height="75dp" 
      android:id="@+id/F" 
      tools:text="@string/faq" 
      tools:textColor="#ffffff" 
      tools:textSize="100px" 

      android:textAppearance="@style/TextAppearance.AppCompat" 
      android:layout_weight="0.02" /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="130px" 
      tools:text="@string/hwr" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      tools:textStyle="bold" 
      /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="300px" 
      tools:text="@## `string/hwr2" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="130px" 
      tools:text="@string/foss" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      tools:textStyle="bold" 
      /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="269dp" 
      tools:text="@string/foss2" 
      tools:textColor="#fff" 
      tools:textSize="40px" /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="130px" 
      tools:text="@string/work1" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      tools:textStyle="bold" 
      /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="300px" 
      tools:text="@string/work2" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="130px" 
      tools:text="@string/free" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      tools:textStyle="bold" 
      /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="300px" 
      tools:text="@string/free2" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="46dp" 
      tools:text="@string/git" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      tools:textStyle="bold" 
      /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="300px" 
      tools:text="@string/git2" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      /> 
     <TextView 
      android:layout_width="394dp" 
      android:layout_height="50dp" 
      tools:text="@string/gsoc" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      tools:textStyle="bold" 
      /> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="700px" 
      tools:text="@string/gsoc2" 
      tools:textColor="#fff" 
      tools:textSize="40px" 
      /> 
    </LinearLayout> 
</ScrollView> 

`

回答

0

android:屬性替換您的各種tools:屬性。

使用tools命名空間只有由Android Studio設計預覽窗口使用。這允許您執行諸如指定佔位符文本之類的事情,以便您可以看到它的外觀......而無需指定可能在現實世界中錯誤顯示的實際用戶可見文本。

藉此TextView的:

<TextView 
     android:layout_width="match_parent" 
     android:layout_height="130px" 
     tools:text="@string/hwr" 
     tools:textColor="#fff" 
     tools:textSize="40px" 
     tools:textStyle="bold" 
     /> 

因爲所有的過去的四個屬性的使用tools命名空間,它們實際上不會有任何效果,當你運行應用程序。這是與具有這樣寫(只要您運行的應用程序而言):

<TextView 
     android:layout_width="match_parent" 
     android:layout_height="130px" 
     /> 

現在,只用android替換所有tools命名空間:

<TextView 
     android:layout_width="match_parent" 
     android:layout_height="130px" 
     android:text="@string/hwr" 
     android:textColor="#fff" 
     android:textSize="40px" 
     android:textStyle="bold" 
     /> 
0

添加到奔普的答案,可能的罪魁禍首是:

  1. 檢查你的背景顏色,因爲你設置文本顏色爲白色,確保它們有對比。
  2. 作爲LinearLayout中的取向是垂直的,使用的是重量總和其最好是有layout_height="0dp"在水平取向的情況下具有寬度0dp。
  3. 如果指定weightsum確保layout_weight加起來的價值,你可以省略由系統通過考慮組部件的個體重量自動計算百分比weightsum。
  4. 另外,作爲小部件的TextView你不能看到垂直方向太大的區別,所以我已經改變了下面的XML定向水平,以便在設備上或在佈局預覽窗口中運行,而你可以清楚地看到的重量差。

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    > 
    <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/F" 
        android:text="hello1" 
        android:textSize="60px" 
        android:textAppearance="@style/TextAppearance.AppCompat" 
        android:layout_weight="1" /> 
    <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="hello1r" 
        android:textSize="40px" 
        android:textStyle="bold" 
        android:layout_weight="4" 
        /> 
    
    <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="hello3" 
        android:layout_weight="1" 
        android:textSize="40px" 
        /> 
    
    <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="hello4" 
        android:layout_weight="2" 
        android:textSize="40px" 
        android:textStyle="bold" 
        /> 
    
    <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_weight="2" 
        android:text="hello5" 
        android:textSize="40px" />