2016-03-02 40 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

相关问题