2011-11-29 147 views
3
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@style/bag" 
    android:layout_height="fill_parent" android:layout_width="fill_parent" 
    android:orientation="vertical" > 

<RelativeLayout 
     android:id="@+id/relativeLayout2" 
      style="@style/relbag" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <TextView style="@style/CodeFont" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_marginLeft="25dp" 
     android:layout_marginTop="18dp" 
     android:textSize="15dp" 
     android:text="General Preference" 
     android:id="@+id/genpref"> 
     </TextView> 


    <ListView 
     android:id="@+id/settingsListView1" 
     style="@style/listbag" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="15dip" 
     android:layout_marginRight="15dip" 

     android:background="@drawable/radius" 
     android:listSelector="@drawable/list_selector" 
     android:paddingTop="8dip" 
     android:paddingBottom="8dip" 
     android:scrollbars="none" 
     android:layout_below="@id/genpref"/> 

     <TextView style="@style/CodeFont" 
     android:id="@+id/notpref" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_marginLeft="25dp" 
     android:layout_marginTop="25dp" 
     android:textSize="15dp" 
     android:text="Notification Preference" 
     android:layout_below="@id/settingsListView1"> 
     </TextView> 


     <ListView style="@style/listbag" android:id="@+id/settingsListView2" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
      android:layout_marginLeft="15dip" android:layout_marginRight="15dip" 
       android:layout_marginBottom="15dip" 
     android:background="@drawable/radius" 
       android:paddingLeft="5dip" android:paddingRight="5dip" 
      android:paddingTop="15dip" android:paddingBottom="15dip" 
      android:listSelector="@drawable/list_selector" 
      android:layout_below="@id/notpref" 
      android:scrollbars="none" 
      /> 
      </RelativeLayout> 
</LinearLayout> 

enter image description here如何做的LinearLayout滚动,而无需使用滚动型

在我的应用我要创建两个列表视图到LinearLayout中,使LinearLayout中滚动不使用滚动型。据我看来,scrollview有一个与listview工作的问题。这张图片不是我想要的,但我们假装在listview下面有另一个listview。所以我想显示listview的所有可用项目(在我的应用程序2列表视图的项目),并使LinearLayout可滚动。 ScrollView不会很好,因为它只能有一个直接的孩子。我找不到解决方案。所以请帮我解决,谢谢

+0

我看到了这样的其他问题不明白w^hy人们希望显示一个ListView,并显示所有可用的列表项。 “ListView”(及其滚动功能)的全部要点是它适合屏幕(或其一部分),并且可以滚动以显示不符合其占用空间的其他项目。如果你想显示一系列'项目',只需为项目创建一个视图,然后创建它的多个动态插入到'ScrollView'中,并忘记使用'ListView'。 – Squonk

+0

参考http://stackoverflow.com/a/17876855/336990 ...可能是有用的 – CoDe

回答

0

使用LinearLayout作为ScrollView的子元素,并将ListView作为子元素放置到LinearLayout。

+2

这不会工作兄弟,我已经试过了。但是,无论如何感谢您的意见 – fish40

+0

在这种情况下,你可以试试这个问题:[多个ListView问题](http://stackoverflow.com/questions/306626/scrolling-with-multiple-listviews-for-android) – SamSPICA

7

我不认为它是一个好主意,把多个列表放在一个单一的屏幕becoz触摸将变得不可思议,使用屏幕将变得复杂。你应该想到别的东西在一个屏幕上显示多个列表。你可以水平排列在一个screen.Romain盖伊(谷歌开发者)多个列表也接受了这一事实在下面的链接....

http://groups.google.com/group/android-developers/browse_thread/thread/77acd4e54120b777

我希望这个答案将帮助ü解决乌尔问题。

0

我thnk这里是您的解决方案,,

你不需要在LinearLayout使用ScrollView

LinearLayout

由于layout_weight PARAM使用layout_weight PARAM在childviews(在你的情况下,两个列表视图)不RelativeLayout提供你需要LinearLayout去改变它。

你可以像下面,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@style/bag" 
    android:layout_height="fill_parent" android:layout_width="fill_parent" 
    android:orientation="vertical" > 

<LinearLayout 
     android:id="@+id/relativeLayout2" 
      style="@style/relbag" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    android:orientation="vertical"> 

     <TextView style="@style/CodeFont" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_marginLeft="25dp" 
     android:layout_marginTop="18dp" 
     android:textSize="15dp" 
     android:text="General Preference" 
     android:id="@+id/genpref"> 
     </TextView> 


    <ListView 
     android:id="@+id/settingsListView1" 
     style="@style/listbag" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:layout_marginLeft="15dip" 
     android:layout_marginRight="15dip" 
     android:background="@drawable/radius" 
     android:listSelector="@drawable/list_selector" 
     android:paddingTop="8dip" 
     android:paddingBottom="8dip"/> 

     <TextView style="@style/CodeFont" 
     android:id="@+id/notpref" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_marginLeft="25dp" 
     android:layout_marginTop="25dp" 
     android:textSize="15dp" 
     android:text="Notification Preference"> 
     </TextView> 


     <ListView style="@style/listbag" 
     android:id="@+id/settingsListView2" 
     android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
       android:layout_marginLeft="15dip" 
     android:layout_marginRight="15dip" 
       android:layout_marginBottom="15dip" 
      android:background="@drawable/radius" 
       android:paddingLeft="5dip" android:paddingRight="5dip" 
       android:paddingTop="15dip" android:paddingBottom="15dip" 
       android:listSelector="@drawable/list_selector"/> 

    </LinearLayout> 
</LinearLayout> 

更改您与上面的XML ..我还没有测试,所以他们可能是你可以轻松解决则params的一些愚蠢的错误..

0

我用这一点,并帮我

ListAdapter listAdapter = listView.getAdapter(); 
int rows = listAdapter.getCount(); 
int height = 60 * rows; // Insert the general cell height plus the dividers. 

ViewGroup.LayoutParams params = listView.getLayoutParams(); 
params.height = height; 
listView.setLayoutParams(params); 
listView.requestLayout(); 

希望帮助ü太

相关问题