Set an ImageView outside the screen with a LinearLayout

2.2k views Asked by At

I'm developing an Android 2.2 application.

I have a linearlayout with a textview, a button and an ImageView.

I want to set this imageview outside of the screen and set an animation to move it from left to right.

I want to simulate a ship moving from left to right. The user will see it appears from left side of the screen and disappears from right side.

I know I can use AbsoluteLayout to set a layout_x for ImageView, but I don't want to set layout_x and layout_y for the others views (textview and button), because they are centred on the screen.

1

There are 1 answers

0
VansFannel On BEST ANSWER

This is how I have solved my problem:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView 
        android:id="@+id/appNameTextView"
        android:text="@string/app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="40px"/>
    <Button
        android:id="@+id/PlayButton"
        android:text="@string/play"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="40px"/>
    <AbsoluteLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <ImageView
            android:id="@+id/greekShip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/picture"
            android:maxWidth="176px"
            android:maxHeight="87px"
            android:layout_x="-200px"/>
    </AbsoluteLayout>
</LinearLayout>