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

android – ScrollView不滚动

我在FrameLayout中有一个ScrollView. ScrollView有一个子LinearLayout.我正在以编程方式将ImageViews添加到此LinearLayout.我希望scrollview水平滚动.

<FrameLayout 
                        android:id="@+id/imgScroll"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/avatar_block">

                        <ScrollView
                            android:id="@+id/avatarScrollView"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" 
                            android:layout_gravity="center" 
                            android:fillViewport="true"> 

                            <LinearLayout
                                android:id="@+id/scrollLayout"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content" 
                                android:gravity="left">


                            </LinearLayout>
                        </ScrollView>

                        <RelativeLayout 
                         android:layout_width="match_parent"
                             android:layout_height="match_parent">
                                     <!-- 2 ImageViews -->
                        </RelativeLayout>
    </FrameLayout>

这就是我添加ImageViews的方式(目前将图像硬编码为drawables)

LinearLayout inScrollLayout = (LinearLayout) findViewById(R.id.scrollLayout);
for(int i = 0; i < imgArray.length; i++)
{
    ImageView imgView = new ImageView(this);
    imgView.setimageResource(R.drawable.icon);  
    imgView.setPadding(0, 0, 40, 0);
    inScrollLayout.addView( imgView);
}

ImageViews被添加到布局中,但最后一个图像缩小了它的大小,我无法滚动.

解决方法:

ScrollView不会水平滚动,您需要HorizontalScrollView.

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

相关推荐