2012-07-01 33 views
0

我正在使用以下配置,以適當地適合滾動視圖內的圖像。android圖像和滾動視圖內的按鈕

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scrollbars="vertical" > 

    <ImageView 
     android:id="@+id/textNimbo" 
     android:layout_width="match_parent" 
     android:layout_height="2492dp" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/inicio" 
     android:adjustViewBounds="true" /> 

</ScrollView> 

但是我需要在scrollView和ImageView下面設置一個按鈕。我嘗試了scrollView內的相對和線性佈局,但沒有成功,按鈕不可見或圖像不適合scrollView。任何推薦的配置?謝謝。

回答

2

ScrollView只能有一個直接子元素。所以要加一個按鈕和一個ImageView的,你需要這樣的事:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scrollbars="vertical" > 

<LinearLayout 
     android:id="@+id/layout" 
     android:layout_width="fill_parent" 
     android"layout_height="fill_parent"> 

    <ImageView 
     android:id="@+id/textNimbo" 
     android:layout_width="match_parent" 
     android:layout_height="2492dp" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/inicio" 
     android:adjustViewBounds="true" /> 
    <Button 
     android:id="@+id/button1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 
</ScrollView> 
+0

已經嘗試過,但沒有工作,按鈕不可見,圖像不適合滾動內容 – Jaume

+0

我試過上面的代碼,它完美的作品。你是否從Java端修改了任何東西? –

0

你也可以使用ImageButton我 而不是ImageView上有一個透明的Button