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

设置子元素以填充horizo​​ntalscrollview的宽度

基本上,我有一个水平滚动视图,它通过监视onTouch事件来进行分页(即:滚动视图(页面)的每个可见部分在滚动时都会“点击”到下一个页面,而不仅仅是具有标准的ScrollView. iOS中的滚动视图).

现在,我想找到一种方法,使内部子类继承与scrollview相同的宽度(在“ fill_parent”中设置).

这是我的XML帮助:

<horizontalscrollview
        android:id="@+id/scrollview"
        android:layout_height="0dp" 
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/scrollviewbg">

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

            <ImageView
                android:src="@drawable/content1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <ImageView
                android:src="@drawable/content2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <ImageView
                android:src="@drawable/content3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </horizontalscrollview>

如您所见,scrollview设置为fill_parent的宽度,并且其中包含LinearLayout.现在,现在有三幅图像,其宽度和高度与屏幕的宽度相似,但是我要做的是更改3个LinearLayouts的宽度和高度.

每个LinearLayout都需要继承与滚动视图相同的宽度,以便在应用我的代码时每个人都占据一个完整的“页面”.

我该怎么做?使用代码要做些什么吗?我需要什么代码

谢谢.

解决方法:

我知道它不是直接的答案,但是它对于使用分页功能Compatibility Package用户ViewPager来说要容易得多.您可以在示例文件夹中找到一个示例(有关源代码,请参见src / com / example / android / supportv4 / app / FragmentPagerSupport.java).

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

相关推荐