2012-10-31 187 views
3

我在FrameLayout中有一个ScrollView。 ScrollView有一个孩子LinearLayout。我以编程方式将ImageView添加到此LinearLayout。我希望scrollview水平滚动。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(目前硬编码的图像绘制资源)

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被添加到布局,但最后的图像缩小它的大小,我不能滚动。

+1

高度应该match_parent而不是wrap_content – njzk2

+0

或设置的dp值。您不应该将任何可滚动视图设置为wrap_content。 – AedonEtLIRA

回答