Radek
Radek

Reputation: 329

Android scroll view / background image / Xamarin

I would like to create scroll view with background image size bigger than screen to do kind of "long scroll page" app. I am using following XML for layout :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="match_parent"
    p1:layout_height="match_parent"
    p1:id="@+id/relativeLayout1">
    <ScrollView
        p1:minWidth="25px"
        p1:minHeight="25px"
        p1:layout_width="wrap_content"
        p1:layout_height="wrap_content"
        p1:id="@+id/scrollView1"
        p1:background="@drawable/wallpaper"

        />
</RelativeLayout>

My wallpaper (background image size is 1920x820.

Question : Why my background on running app is always adjusted to screen size if I use scroll view tag?

What I want to achieve : Same effect like here : http://developer.xamarin.com/recipes/ios/content_controls/scroll_view/use_a_scrollview/

Testing env Nexus 4 simulator

Upvotes: 1

Views: 1555

Answers (1)

William Barbosa
William Barbosa

Reputation: 5005

The scrollable content is whatever is inside your ScrollView. In this case, all you have to do is create a ImageView inside your ScrollView and set is src attribute to @drawable/wallpaper:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="match_parent"
    p1:layout_height="match_parent"
    p1:id="@+id/relativeLayout1">
    <ScrollView
        p1:minWidth="25px"
        p1:minHeight="25px"
        p1:layout_width="wrap_content"
        p1:layout_height="wrap_content"
        p1:id="@+id/scrollView1">

        <ImageView
            p1:layout_width="wrap_content"
            p1:layout_height="wrap_content"
            p1:src="@drawable/wallpaper"/>
        </ScrollView>
</RelativeLayout>

Ps: I'd also change "p1" to "android", as it's the commom way of naming and avoid using px

Upvotes: 1

Related Questions