Gooey
Gooey

Reputation: 4778

Android - place views outside screen

I just made this FrameLayout with in it a very large picture as you can see that is a map. I'd like to place Views (Buttons, ImageViews) outside the screen, so that an user has to scroll in order to 'find' them on the map. I'm using this to scroll around on the map: Android: Scrolling an Imageview

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000" >

    <ImageView
        android:id="@+id/map"
        android:layout_width="2500dp"
        android:layout_height="2000dp"
        android:src="@drawable/map" />
</FrameLayout>

When i try to add a button programmatically or just putting it in the XML, it only shows when it's margin-left and margin-top position are withing the dimensions of the screen. (480 by 800 i believe). If I add e.g. a button outside these dimensions the view wont show, not even when scrolled towards it. The solution at FrameLayout margin not working doesn't work either.

Adding this works:

<Button
        android:id="@+id/one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/one"
        android:layout_marginLeft="420px"
        android:layout_marginTop="240px"
        android:layout_gravity="top"
        android:onClick="click" />

Modify it like this and it wont show anymore, even when scrolling towards it:

<Button
        android:id="@+id/one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/one"
        android:layout_marginLeft="1290px"
        android:layout_marginTop="940px"
        android:layout_gravity="top"
        android:onClick="click" />

It doesn't matter if I use pixels or dp, the view is not showing at all.

I have no clue why this is, but I would love to hear a solution. Any help is appreciated.

Upvotes: 2

Views: 931

Answers (1)

Desert
Desert

Reputation: 2303

The reason why this is not working right now is because your FragmeLayout width and height are too small when using fill_parent and you are trying to add button to the place where it already ended.

And also what you are really doing by using solution Android: Scrolling an Imageview is only setting new scroll position of ImageView (you are not scrolling FragmeLayout itself).

The solution for your problem is to set layout_width and layout_height of your parent to the width and height of your ImageView and use onTouchListener from Android: Scrolling an Imageview to the whole FrameLayout.

Upvotes: 1

Related Questions