在android中的Scrollview中设置Viewpager高度 [英] Set Viewpager height inside Scrollview in android

查看:296
本文介绍了在android中的Scrollview中设置Viewpager高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在scrollview中显示viewpager(在分页器行中图像下方的图像和文本).我正在从网上下载图像,文本并在寻呼机行中显示.我也将viewpager包装在srollview中以支持横向模式.

I have to show a viewpager (An image and text below the image in pager row) inside a scrollview. I'm downloading the image, text from web and showing in pager rows. I wrapped viewpager inside a srollview to support the landscape mode too.

 <com.xxx.myapp.android.ui.CustomScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:fadingEdge="none"
    android:fillViewport="true"
    android:gravity="center">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:descendantFocusability="blocksDescendants"
        android:orientation="vertical" >

        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="800dp"
            android:layout_gravity="top"
            android:layout_marginTop="10dp" />  
    </LinearLayout>
</com.xxx.myapp.android.ui.CustomScrollView> 

这是 CustomScrollView .问题是如何根据子页面的高度设置视图寻呼机的高度,以便我可以滚动屏幕,直到视图寻呼机项仅结束.如果我将视图寻呼机的高度设置为wrapcontent,则viewpager中什么也没有显示.如果我设置为800dp,则可以看到寻呼机项目,但屏幕上没有不必要的滚动.我不希望我的scrollview滚动到超过寻呼机儿童的高度.请帮我.

And here is CustomScrollView. The problem is How can I set the view pager height based on its children height so that I can scroll the screen till the view pager item ends only. If I set view pager height to wrapcontent, nothing is showing in viewpager. If I set some 800dp then I can see the pager items but there is unnecessary scrolling in the screen. I dont want my scrollview to be scrolled beyond the pager childrens height. Please help me.

推荐答案

将分页器行包装在CustomScrollView中,而不是将分页器包装在CustomScrollview中.而且不要像Piyush Gupath所说的那样固定Viewpager的高度.使用wrapcontent.

Wrap your pager row inside CustomScrollView instead of wrapping the pager inside CustomScrollview. And Don't fix height of Viewpager as Piyush Gupath commented. Use wrapcontent.

这篇关于在android中的Scrollview中设置Viewpager高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆