2017-05-04 44 views
0

我的Android應用包含地圖用戶應該滾動水平垂直看到這一切。 我已經使用了兩個水平和垂直滾動視圖,並且其中包含圖片視圖。 但問題是,圖片沒有完整顯示在佈局和頂部邊距和左邊距的一部分被隱藏(剪切)。 所以我的問題是:圖像邊緣被切割成了滾動

  1. 如何在滾動視圖中完全顯示圖片而不削減邊距? The problem is shown is this picture
  2. 當我開始應用在第一個滾動視圖中的圖像是而不是縮放!並且觸摸事件在其大小後變大。

代碼:

<HorizontalScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="100dp" 
    android:layout_marginTop="150dp" 
    android:scrollbarStyle="outsideOverlay" 
    > 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_gravity="center" 
     android:gravity="center"> 

     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:scrollbarStyle="outsideOverlay"> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:layout_gravity="center" 
       android:gravity="center"> 
       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        app:srcCompat="@android:drawable/ic_input_add" 
        android:id="@+id/imageView2" 

        android:gravity="center_vertical|center_horizontal" 
        /> 

      </RelativeLayout> 
     </ScrollView> 

    </RelativeLayout> 
</HorizontalScrollView> 
+0

我也用線性佈局而不是相對佈局,但沒有發生變化! –

+0

感謝您的幫助。這對我在第二個問題中有幫助,[鏈接](http://stackoverflow.com/questions/16440863/can-i-get-image-file-width-and-height-from-uri-in- Android),但第一個問題仍然存在,我認爲佈局或滾動視圖之一導致此問題。 –

+0

它看起來像這是你在尋找 http://android-er.blogspot.in/2014/01/horizo​​ntal-vertical-scrollable-view.html – shijin

回答

0

嘗試改變外相對佈局的寬度和高度符合母體。 你更新後的代碼應該是這樣的:

<HorizontalScrollView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_marginBottom="100dp" 
android:layout_marginTop="150dp" 
android:scrollbarStyle="outsideOverlay" 
> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:gravity="center"> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scrollbarStyle="outsideOverlay"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:gravity="center"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       app:srcCompat="@android:drawable/ic_input_add" 
       android:id="@+id/imageView2" 

       android:gravity="center_vertical|center_horizontal" 
       /> 

     </RelativeLayout> 
    </ScrollView> 

</RelativeLayout> 

+0

不幸沒有幫助我,錯誤仍然只是描述。 。我也嘗試了fill_parent或其他配置,如負邊距,但沒有發生變化。 –

+0

答案錯了 從位圖中實時獲取圖像的寬度和高度。 以編程方式將該寬度和高度設置爲imageview。 – shijin

+0

將pad添加到內部線性佈局會改善問題,但相對視圖會損壞x座標,儘管y座標是正確的。 –