2013-05-06 77 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