微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 在horizo​​ntalScrollView中的布局是屏幕的大小

我是 Android的新手,一直在寻找一个解决方案,但到目前为止没有运气.我想创建一个类似下面的图片的布局.

我想要一个linearLayout是屏幕的大小.然后有另一个linearLayout也是屏幕的大小,但关闭屏幕.我可以在两个虚拟“屏幕”之间滚动. (我要显示图像,但是,由于我是新的网站,我不被允许…链接到图像是here

有一篇有趣的文章解释了如何扩展scrollView类,以便我可以得到一个很酷的捕捉效果,所以如果我可以得到这个工作,我的应用程序将感觉很像在主屏幕之间滚动.

我已经阅读了关于权重,还有关于scrollView的fillViewport =“true”.我恐怕我不明白如何使用horizo​​ntalScrollView来让linearLayouts填满屏幕.我尝试过各种各样的fill_parent和wrap_content的组合,但是没有用.

正如我所看到的那样,只要我构建子视图(每个“屏幕”中的元素),并考虑到屏幕变异性,这个功能就不会影响应用在具有不同屏幕的设备之间的可移植性.

以下是我正在尝试的XML的简单示例:

<horizontalscrollview
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/horizontalscrollview01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true">

<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/txtTestBox"
            >
        </EditText>
    </LinearLayout>

    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button 1"
        />

    </LinearLayout>

</LinearLayout>

</horizontalscrollview>

不幸的是,这甚至没有接近我正在寻找的东西.希望这可以做到…

感谢任何帮助或建议.

解决方法

水平滚动视图可以无限地缩放到一边,所以“填充父”很可能不会像您在内部布局中所期望的那样工作.您是否尝试在内部布局上明确指定宽度?

就像是:

<horizontalscrollview
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/horizontalscrollview01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true">

<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="400dp"
    android:layout_height="fill_parent">

.....

</LinearLayout>


</horizontalscrollview>

原文地址:https://www.jb51.cc/android/311586.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐