2013-05-06 78 views
2

我試圖爲我的應用程序構建一個gui。它由兩個圖像組成,一個在另一個的上面。底部圖像需要滾動,頂部圖像需要修復。可滾動和不可滾動的圖像

這是考慮到當前的佈局的xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="right" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/button_load" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Load" /> 

     <Button 
      android:id="@+id/button_save" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Save" /> 
    </LinearLayout> 

    <uk.co.test.EditorView 
     android:id="@+id/EditorView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" /> 

    <HorizontalScrollView 
     android:id="@+id/scroll_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="bottom" > 

     <ImageView 
      android:id="@+id/image_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:src="@drawable/imagemdpi" /> 
    </HorizontalScrollView> 

</LinearLayout> 

使用這種佈局中,底部圖像不滾動,它被壓縮到屏幕的寬度。如果我刪除了EditorView,它會滾動。我如何根據需要製作gui?

任何幫助感激地收到。謝謝

回答

2

我實際上不知道爲什麼刪除EditorView使它工作。另外,我只在佈局中看到一個圖像視圖。但爲了使該ImageView水平滾動,我會將滾動視圖的layout_width更改爲「match_parent」,並將縮放類型添加到圖像視圖中。

(參見:https://developer.android.com/reference/android/widget/ImageView.ScaleType.html

我會嘗試無論是「中心」或「矩陣」,雖然平時我有玩弄這一點得到我怎麼想它,它只是工作。 這樣:

<HorizontalScrollView 
    android:id="@+id/scroll_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="bottom" > 

    <ImageView 
     android:id="@+id/image_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="center" 
     android:layout_gravity="bottom" 
     android:src="@drawable/imagemdpi" /> 
</HorizontalScrollView> 

在總體上,隨着滾動的意見,要match_parent滾動視圖的大小,但被滾動WRAP_CONTENT的視圖。滾動視圖允許包裝視圖比自己的邊界變大,但如果滾動視圖比屏幕邊界增大,它將不會滾動,因爲它認爲它已經顯示了所有內容。

+0

感謝您的幫助,它現在工作:)。 EditorView包含一個ImageView,我認爲我會嘗試將ImageView放入,並根據您的建議將Horizo​​ntalScrollView的layout_width設置爲match_parent,並使用「center」將scaletype放入。 再次感謝。 – JulioM 2013-05-06 22:13:34

+1

@JulioM請接受我的答案,如果它適合你。它有助於我的聲譽,並且如果他們有類似的問題,也可以幫助未來的用戶找到正確的解決方案。 – 2013-05-07 15:33:54

+0

........好的...... – JulioM 2013-05-07 20:39:08