我有了一个LinearLayout里面ScrollView一个android:layout_height="fill_parent",但它并没有扩展到ScrollView的整个高度。我的布局看起来像:

level    layout    layout_width    layout_height
1    LinearLayout    fill_parent    fill_parent
2    LinearLayout    fill_parent    wrap_content
3    (some irrelevant stuff)
2    ScrollView      fill_parent    fill_parent <-- this expands full height
3    LinearLayout    fill_parent    fill_parent <-- this does not (has orientation=vertical)
(following stuff probably are irrelevant, but just to be sure:)
4    TextView        fill_parent    fill_parent
4    LinearLayout    fill_parent    wrap_content

我可以看到LinearLayout不扩大ScrollView的全高度,因为在Eclipse中Android Layout Editor,如果我选择了ScrollView(大纲面板),它的显示使用,填补了屏幕底部的红色边框但是当我选择LinearLayout其亮点并不扩展到屏幕的底部。我怎样才能得到它这样做?

我想达到的效果是有一些文本和(4级LinearLayout内有只是一个按钮)下方的按钮。该文本可以是足够大需要一个滚动条,在这种情况下,我希望用户必须以看到该按钮向下滚动。在情况下,文本不够大了滚动条,我想包含按钮粘到屏幕底部的LinearLayout

起初我还以为我不应该发布完整的XML,因为它通常是一转,即可查看代码大块中的问题。然而,现在看来,这可能是必要的,所以这里的完整布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/video_layout"
        android:focusable="true"
        style="@style/VideoLayout">
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:foreground="@android:drawable/ic_media_play"
            android:foregroundGravity="center">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/video_thumb"
                android:padding="5dip"
                android:background="#454545"/>
        </FrameLayout>
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:focusable="true"
            style="@style/VideoTitle"
            android:id="@+id/video_title"
            android:layout_gravity="center"
            android:layout_weight="1"/>
    </LinearLayout>
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <!-- this ScrollView expands the full height of the screen.
             However, the next LinearLayout does not expand the full height of the ScrollView -->
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:layout_gravity="fill"
            android:orientation="vertical"
            android:id="@+id/info_layout">
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/info_body"
                style="@style/InfoText"/>
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                style="@android:style/ButtonBar">
                    <Button
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_weight="1"
                        android:text="@string/button_readmore"
                        android:id="@+id/btn_read_more"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

目前我已经使出android:layout_gravity="bottom"的问题LinearLayout,这使得按键贴到屏幕底部无论什么时刻。但是,这也使得文本贴到屏幕的底部,这不正是我之后。

<强>更新划痕的是,android:layout_gravity="bottom"使ScrollView无法,井,滚动。其他的想法?

有帮助吗?

解决方案

找到的解自己到底。问题是不与LinearLayout,但与ScrollView(似乎不可思议,考虑到一个事实,即ScrollView 扩大,而LinearLayout不是)。

<强>的解决方案是在android:fillViewport="true"使用ScrollView

其他提示

我知道这个职位是很老了,对于那些谁不希望使用android:fillViewport="true",因为它有时并不带来了键盘上方的EditText上。 使用相对布局代替的LinearLayout它解决了目的。

您可以提供您的布局XML?这样做可以让人们以最小的努力重现该问题。

您可能需要设置

android:layout_weight="1"
你想扩展

有关项目

我动态地使用以获得这一点。我有一个的LinearLayout并在此使用滚动型作为一个孩子。然后我去一次的LinearLayout,并添加什么都看ü要这个的LinearLayout,然后这个LinearLayout中添加滚动型,最后这个滚动型增加的LinearLayout。那么在哪里在乌拉圭回合滚动型获得滚动什么都不会留下可见的。

的LinearLayout(母公司) - 滚动型(LinerLayout儿童) - 的LinearLayout(滚动型的孩子) - 在这里补充的TextView,按钮,微调等什么ü希望。那么这LinearLyout添加到滚动型。 Bcoz了滚动适用,最后添加本滚动型到LinearLyout.If定义区域只有一个孩子是从屏幕尺寸超过则U将在滚动型得到滚动。

在我的情况下我还没有给出的

  

的LinearLayout(滚动型的儿童)的取向

所以,在默认情况下它需要的水平,但滚动型scrols垂直,所以请检查“机器人:方向=‘垂直’”设为您的滚动型的孩子(在LinearLayout中的情况下)

  

这是我的情况下,希望它可以帮助别人

的解决方案是使用

android:fillViewport="true"

上的滚动视图并此外尝试使用

"wrap_content"代替"fill_parent"作为"fill_parent"

现在已经过时。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top