简体   繁体   English

Android ListView无法正确缩放

[英]Android ListView not scaling properly

I am new to android programming and I came across a problem I can not solve. 我是android编程的新手,遇到了我无法解决的问题。 I googled it for a while but did not find the sollution to my scenario. 我用谷歌搜索了一段时间,但没有找到解决方案。 Far as I understand ListViews in android are adopting their size based on the space on the screen, but what if I need more space. 据我了解,Android中的ListView正在根据屏幕上的空间采用其大小,但是如果我需要更多空间该怎么办。

I have a layout like below on picture and problem is that second ListView is only one item big and then you need to scroll, but I want it to be at least few (visible - non scroll) items. 我在图片上有下面的布局,问题是第二个ListView只有一个大项目,然后您需要滚动,但我希望它至少是几个(可见-非滚动)项目。 I do not want it to make fixed height. 我不希望它达到固定的高度。 But even if I do then still it goes out of the visible area, which forces me to make a ScrollView which again does not work with ListViews. 但是,即使我这样做了,它仍然超出了可见区域,这迫使我制作了一个ScrollView,它再次不适用于ListViews。

So I am quite lost. 所以我很迷路。 Please for guidance 请指导

在此处输入图片说明

You could put both listviews with weights into a LinearLayout. 您可以将两个带有权重的列表视图放入LinearLayout中。 See second picture: http://android4beginners.com/wp-content/uploads/2013/07/android_studio_linear_layout_example.png 参见第二张图片: http : //android4beginners.com/wp-content/uploads/2013/07/android_studio_linear_layout_example.png

All you need to do is set the weights of the listviews according to the design you were looking for. 您需要做的就是根据要寻找的设计设置列表视图的权重。

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_rel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="2.0" >

    <ListView
        android:id="@+id/child_one"
        android:layout_width="match_parent"
        android:layout_height="0"
        android:layout_weight="1.0"
        android:background="#0000FF" >
    </ListView>

    <ListView
        android:id="@+id/child_two"
        android:layout_width="match_parent"
        android:layout_height="0"
        android:layout_weight="1.0"
        android:background="#00FF00" >
    </ListView>

</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM