2013-02-22 119 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,假));

相關問題