2016-03-02 35 views
1

我的應用程序有兩個部分,今天要做的事情和即將到來的日子。無法使ScrollView在應用程序中工作

我可以通過按下相應的按鈕來隱藏/顯示這些信息,但是當我同時打開這兩個信息時,可能會有太多信息,我只能滾動列表視圖來查看即將到來的日子,而不是整個屏幕。

我做了一些搜索,我不斷看到ScrollView彈出,但我無法讓它工作,它崩潰了我的應用程序。

這裏是我的XML文件

<?xml version="1.0" encoding="utf-8"?> 
<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" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context="eu.agp_it.agpmobilemover.OverviewActivity"> 
    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="1.0" 
      android:gravity="center" 
      android:id="@+id/layout_button_today"> 
      <Button 
       android:id="@+id/overview_button_today" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.95" 
       android:layout_width="0dp" 
       android:textSize="20sp" 
       android:text="@string/overview_today" 
       android:gravity="center" 
       android:layout_marginTop="5px" 
       android:layout_marginBottom="5px" 
       android:background="@drawable/custom_buttonoverview" 
       android:onClick="buttonTodayOnClick"/> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/layout_listview_today" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/layout_button_today"> 
      <ListView 
       android:id="@+id/listviewtoday" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:dividerHeight="1dp" 

       android:visibility="visible"/> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/layout_button_upcoming" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="1.0" 
      android:gravity="center" 
      android:layout_below="@id/layout_listview_today"> 
      <Button 
       android:id="@+id/overview_button_upcoming" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.95" 
       android:layout_width="0dip" 
       android:textSize="20sp" 
       android:text="@string/overview_upcoming" 
       android:background="@drawable/custom_buttonoverview" 
       android:gravity="center" 
       android:layout_marginTop="5px" 
       android:layout_marginBottom="5px" 
       android:onClick="buttonUpcomingOnClick"/> 
     </LinearLayout> 
     <LinearLayout 
      android:id="@+id/layout_listview_upcoming" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/layout_button_upcoming"> 
      <ListView 
       android:id="@+id/listviewupcoming" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:dividerHeight="1dp" 

       android:visibility="gone"/> 
     </LinearLayout> 
    </ScrollView> 


</RelativeLayout> 
+1

a)你必須發佈你的崩潰日誌。 b)你只能在'ScrollView'內部擁有一個子視圖,你可以在'ScrollView'內部放置一個'LinearLayout',並將所有內容放在該視圖中。 c)你不應該在'ScrollView'裏面放置'ListView' d)你不應該在一個視圖中放置多個'ListView'。 – Sharj

+0

@Sharj但如果我應該在視圖中放置多個ListView,我如何列出今天和即將到來的日子的任務? – Madgarr

+0

你可以在你的'ListView'適配器中處理它。 – Sharj

回答

0

你可能不需要了滾動的。 ListViews已經爲你做了滾動。不建議嵌套滾動視圖。

嘗試取出ScrollView。每個LinearLayout可能會佔用屏幕的一半,或者您想要的任何數量。您也可以使用ExpandableListView,它可以讓您根據標題(今天,即將到來)展開和摺疊今天和即將到來的日子的分配。這樣你只需要一個ListView。所以它會更容易維護。

+0

我會嘗試使用ExpandableListView,感謝您的信息! – Madgarr

+0

剛剛看到了ExpandableListViews的一些示例,我不認爲我可以在它們上放置儘可能多的信息,因爲我需要多個按鈕和多個文本字段,所以我想我可以嘗試使我的解決方案沒有儘可能使用ScrollView。 – Madgarr

相關問題