2013-02-22 158 views
0

很大的差距我有一个Horizo​​ntalScrollView和线性布局在Android的Horizo​​ntalScrollView

<HorizontalScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/filesScrollerLayout" 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
    </LinearLayout> 
</HorizontalScrollView> 

Programmaticaly我尝试添加在LinearLayout中的观点有以下方式:

 LinearLayout layout = (LinearLayout)findViewById(R.id.filesScrollerLayout); 

    ImageView imageView1 = new ImageView(this); 
    ImageView imageView2 = new ImageView(this); 
    ImageView imageView3 = new ImageView(this); 
    imageView1.setImageDrawable(Drawables); 
    imageView2.setImageDrawable(Drawables); 
    imageView3.setImageDrawable(Drawables); 

的问题是,在horizo​​ntalscroll视图中,图像之间存在很大差距。我只是想让图像彼此相邻。我怎样才能成功?

+0

尝试使horizo​​talScrollview宽度wrap_content – 2013-02-22 17:33:05

+0

@Mehul Ranpara我试过了,但它没有工作 – 2013-02-22 17:34:47

+0

图像可能被缩放到比图像视图更小的尺寸。所以图像视图是彼此相邻的,但由于它们的内容较小,所以它们看起来不像。将图像上的scaleType改为fit_start之类的东西,看看是否有帮助 – dymmeh 2013-02-22 17:37:10

回答

0

设定边距和填充到"0dp"

如这里

<HorizontalScrollView 
android:id="@+id/scrollView" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_margin="0dp" 
android:padding="0dp"> 

<LinearLayout 
    android:id="@+id/filesScrollerLayout" 
    android:orientation="horizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="0dp" 
    android:padding="0dp"> 
</LinearLayout> 
</HorizontalScrollView> 
5

如果内容ImageViews,设置此:

android:adjustViewBounds="true" 
0

如果使用在运行时生成的ImageView,使用umagView。 setAdjustViewBounds(真);

0

我也有同样的问题。您必须缩小图像以使其工作。

使用此:

位图B = BitmapFactory.decodeByteArray(imageAsBytes,0,imageAsBytes.length) profileImage.setImageBitmap(Bitmap.createScaledBitmap(B,120,120,假));

相关问题