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>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...