2013-04-22 287 views
2

有人可以解釋爲什麼scrollview不顯示他的子元素? 我有textviews的金潤一的LinearLayout內垂直,也就是LinearLayout中滾動視圖內......ScrollView不顯示內容

但我沒有看到任何滾動視圖既不是textviews ..

這裏是XML佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
     android:id="@+id/description" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/scrollViewCheck" 
     android:gravity="center" 
     android:padding="10dip" 
     android:text="Pick which items you want to count" 
     android:textAppearance="?android:attr/textAppearanceMedium" > 
    </TextView> 

    <ScrollView 
     android:id="@id/scrollViewCheck" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/bottomSettings" 
     android:scrollbarFadeDuration="0" > 

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

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:text="Test" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 
     </LinearLayout> 
    </ScrollView> 

    <RelativeLayout 
     android:id="@id/bottomSettings" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/timeButton" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Choose Count Time" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@id/timeButton" 
      android:orientation="horizontal" > 

      <Button 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Back" /> 

      <Button 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Start" /> 
     </LinearLayout> 
    </RelativeLayout> 

</RelativeLayout> 

在此先感謝;)

回答

2

該視圖的問題與底部的RelativeLayout有關。這應該可以解決您的問題。在這個底部更換的RelativeLayout:

<LinearLayout 
     android:id="@+id/bottomSettings" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_alignParentBottom="true"> 

    <Button 
      android:id="@+id/timeButton" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Choose Count Time" /> 

    <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@id/timeButton" 
      android:orientation="horizontal" > 

     <Button 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Back" /> 

     <Button 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:text="Start" /> 
    </LinearLayout> 
</LinearLayout> 
+0

這固定了整個事情,但哥們有時候我被困在許多佈局......有太多的故障。我的意思是,佈局應該更容易製作,有許多次要的東西會改變整個內容。有什麼方法可以更快更簡單地進行設計嗎? adt活動設計模式並不好.. 謝謝! – TiagoM 2013-04-22 21:36:44

+1

@DarkLink我通常做設計的方式是從一些非常簡單的事情開始,並逐個添加元素。這樣我就知道問題出現在哪裏了。 – Ethan 2013-04-22 21:46:36

+0

是的,這正是我期待的,很多試驗和錯誤,就像David Wasser說的:) 謝謝! – TiagoM 2013-04-22 22:18:24

1

我不認爲你可以定義一個ScrollView高度爲「wrap_content」。由於內容遠大於屏幕上的內容。通常你需要將一個ScrollView的高度定義爲某個固定值。如果你想了滾動佔用儘可能多的屏幕儘可能的,同時還具有頁眉和頁腳的觀點,你可以試試這個:

android:layout_height="1dp" 
    android:layout_weight="1" 

這將基本分配屏幕上所有的剩餘空間ScrollView。我在這裏沒有機器來測試它,但試試看,讓我知道它是如何工作的。

+0

我測試了這個解決方案,它也可以工作!謝謝;) 順便說一句:「有時我會陷入許多佈局......有太多的故障,我的意思是,佈局應該更容易製作,有許多小事情會改變整體內容。有沒有什麼方法可以更快更簡單地設計它?adt活動設計模式並不是很好..謝謝!「 – TiagoM 2013-04-22 21:41:02

+1

我對你沒有任何建議。我不使用ADT的東西,我只是編輯XML並再試一次。我花了很長時間纔開始瞭解不同佈局參數如何相互影響。不幸的是,有許多不同的方法來實現結果,並且在不同的佈局參數之間存在複雜的依賴性和相互作用。 Android的設計人員/開發人員從未覺得需要詳細記錄所有這些依賴關係,所以我們必須通過反覆試驗來弄明白。當然,StackOverflow用戶是一個很大的幫助:-)他們肯定是 – 2013-04-22 21:45:35

+0

!如果沒有像你這樣的成員,我會很遺憾找出爲什麼不起作用,再次感謝! 我明白謝謝你的解釋,讓我們希望他們會發布涵蓋所有小細節的良好文檔:) – TiagoM 2013-04-22 22:17:15

2

您使用的是RelativeLayout作爲根佈局和缺少像android:layout_belowandroid:layout_above佈局指令。

這就是爲什麼這些元素相互重疊,並且您沒有看到您的ScrollView

將您的根佈局更改爲LinearLayout,屬性爲android:orientation="vertical",您將看到所有小部件。

+0

我試過了,也工作;)非常感謝! – TiagoM 2013-04-22 21:42:12