0

我正在开发一个 Android 2.2 应用程序。

我有一个带有 textview、一个按钮和一个 ImageView 的线性布局。

我想将此图像视图设置在屏幕外并设置动画以将其从左向右移动。

我想模拟一艘从左到右移动的船。用户将看到它从屏幕左侧出现并从右侧消失。

我知道我可以使用 AbsoluteLayout 为 ImageView 设置 layout_x,但我不想为其他视图(文本视图和按钮)设置 layout_x 和 layout_y,因为它们在屏幕上居中。

4

1 回答 1

2

这就是我解决问题的方法:

<?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>
于 2011-02-21T18:45:19.187 回答