Jaume Jaume - 4 months ago 23
Android Question

android image and button inside a scrollview

I am using following configuration to properly fit image inside a scrollview.

<?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>


However I need to set also a button inside scrollView and below the ImageView. I tried relative and linear layouts inside scrollView but no succes, button is not visible or image doesn't fit to scrollView. Any recommended configuration? Thank you.

Answer

A ScrollView can only have one direct child element. So to add a Button and an ImageView, you'll need something like this:

<?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>
Comments