Android ScrollView设置显示内容的高度 [英] Android ScrollView set height for displayed content

查看:1635
本文介绍了Android ScrollView设置显示内容的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试解决布局中具有静态高度可滚动区域的问题时,我遇到很多麻烦.我有三个长列表需要在同一屏幕上显示,并且顺序显示所有条目是完全不切实际的,因为如果您要跳过类别,则需要滚动浏览可能的数百个条目.

I'm having a lot of trouble trying solve the issue of having a static height scrollable area within a layout. I have three long lists that need to be displayed on the same screen and it would be entirely impractical to display all of the entries sequentially because then if you want to skip a category you need to scroll past possibly hundreds of entries.

假设我有一个带有线性布局的滚动视图,我希望它占用屏幕上的最大250dp高度,并且一旦填充了超过250dp空间容纳的更多条目,就可以独立滚动.

Assume I have a scroll view with a Linear Layout inside of it, I want this to take up say, 250dp height on the screen at max and be independently scrollable once populated with more entries than can fit in 250dp's space.

我现在拥有的是:

<ScrollView
    android:minWidth="25px"
    android:minHeight="150px"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/XXXXXXX"
    android:scrollbars="vertical">

    <LinearLayout
        android:orientation="vertical"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/XXXXXX" />
</ScrollView>

当填充时,scrollview和linearlayout会拉伸,只要它们需要适合内容并显示所有内容即可,而不是具有250dp/px的窗口"(任何测量方式都是不错),并且其中的内容可以滚动.

When populated, the scrollview and linearlayout just stretch as long as they needs to to fit the content and displays all of it instead of having a "window" of 250dp/px (any measurment would be nice) with the content scrollable within it.

我是android平台的新手,所以答案也许很明显,我只是不懂该语言,但是任何帮助将不胜感激! 谢谢

I'm new to the android platform, so perhaps the answer is obvious and I just didn't understand the language, but any help would be greatly appreciated! Thank you

---已解决: 将linearLayout与高度放在ScrollView的外面.

--- SOLVED: Put a linearLayout outside of the ScrollView with the height.

推荐答案

您需要的是maxHeight.但是由于视图不支持该视图,因此您必须使用一种解决方法.

What you need is a maxHeight. But since views do not support it, you have to use a workaround.

查看此答案:

https://stackoverflow.com/a/13811461/770467

这篇关于Android ScrollView设置显示内容的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆