2015-08-18 47 views
-1

im使用picasso將大圖像加載到imageview中,但我希望它坐在視圖的中心,但現在它與開始位置對齊(左上角)通過XML我用盡alsorts沒有成功,圖像視圖是滾動視圖和水平滾動視圖像這裏面如何在scrollview和水平滾動視圖中居中放置圖像android

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/scrollcontainer"> 

     <HorizontalScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/upydownyscrolleyscrolley"> 

      <ScrollView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/leftyrightyscrolleyscrolley" 
       > 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:id="@+id/imagecontainer"> 

       <ImageView 
        android:id="@+id/wallImage" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

       </LinearLayout> 

      </ScrollView> 
     </HorizontalScrollView> 
    </RelativeLayout> 

一些圖片太大,無法橫向屏幕,一些是太大垂直,所以我遇到了一個方式來實現它的編程,但它不工作我試圖使用scrollviews的寬度和高度,這並沒有工作,所以我試圖得到像這樣的圖像視圖的高度和寬度,

int centerX = WallpaperView.getWidth()/2; 
int centerY = WallpaperView.getHeight()/2; 
scrollView.scrollTo(centerX, centerY); 

但是再次沒有快樂,我不知道這是因爲畢加索還沒有加載視圖,儘管我打電話給調用畢加索後,有沒有人可以幫助我?

回答

0

試試這個佈局:

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/scrollcontainer"> 

    <HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/upydownyscrolleyscrolley"> 

     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@+id/leftyrightyscrolleyscrolley"> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="horizontal" 
       android:id="@+id/imagecontainer"> 

      <ImageView 
       android:id="@+id/wallImage" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:scaleType="centerInside" 
       android:gravity="center" /> 

      </LinearLayout> 

     </ScrollView> 
    </HorizontalScrollView> 
</RelativeLayout> 

如需更多幫助,請在此:http://etcodehome.blogspot.com/2011/05/android-imageview-scaletype-samples.html

+0

沒有工作不太大的圖像(身高超過設備屏幕,寬於設備屏幕)仍然從左上角開始這些意見嵌套在框架佈局設置爲填寫父,但我不知道如何可能會影響它 –

+0

把它拿出來,並使其頂視圖,但沒有區別 –