2011-06-15 134 views

回答

0

你可以使用這個,

在XML使用horizo​​ntalscrollView

<HorizontalScrollView 
android:layout_width="match_parent" 
android:layout_height="100dp" 
android:layout_marginTop="10dp" 
android:layout_marginBottom="10dp" 
android:paddingLeft="15dp" 
android:paddingRight="15dp" 
android:id="@+id/hrscroll"> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:id="@+id/scrollview_layout"> 

</LinearLayout> 

</HorizontalScrollView> 

Java代碼

..

 LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT); 
     params.width=110; 
     LayoutParams params2 = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT); 
     params2.width=100; 
     LinearLayout gall = (LinearLayout) findViewById(R.id.scrollview_layout); 
     for(int i=0;i<=5;i++){ 
     LinearLayout Limages = new LinearLayout(this); 
     Limages.setOrientation(LinearLayout.VERTICAL); 
     ImageView images = new ImageView(this); 
     // images.setScaleType(ImageView.ScaleType.FIT_CENTER); 
     images.setLayoutParams(params2); 
     images.setBackgroundResource(R.drawable.imagez); 
     Limages.addView(images); 
     Limages.setLayoutParams(params); 
     gall.addView(Limages); 
     } 
相關問題