• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

android - LinearLayout 未在 ScrollView 内扩展

[复制链接]
菜鸟教程小白 发表于 2022-8-1 01:21:12 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个 LinearLayoutScrollView 内有 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"
    androidrientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        androidrientation="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"
            androidrientation="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"
                androidrientation="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无法滚动。其他想法?



Best Answer-推荐答案


最后自己找到了解决方案。问题不在于 LinearLayout ,但使用 ScrollView (看起来很奇怪,考虑到 ScrollView 正在 扩展,而 LinearLayout 没有)。

解决方案是使用 android:fillViewport="true"ScrollView .

关于android - LinearLayout 未在 ScrollView 内扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2599837/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap