Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 在horizo​​ntalScrollView中的布局是屏幕的大小大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 Android的新手,一直在寻找一个解决方案,但到目前为止没有运气.我想创建一个类似下面的图片的布局.

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

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

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

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

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

<horizontalscrollview
xmlns:android="http://scheR_950_11845@as.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://scheR_950_11845@as.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>

大佬总结

以上是大佬教程为你收集整理的android – 在horizo​​ntalScrollView中的布局是屏幕的大小全部内容,希望文章能够帮你解决android – 在horizo​​ntalScrollView中的布局是屏幕的大小所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。