1

我目前正在为安卓开发一款游戏。

我有三个彼此相邻的 ImageView,它们使用“android:layout_toRightOf”彼此相邻定位。这些视图位于 RelativeLayout 标记内。这些视图中的每一个都使用“android:scaleType="fitCenter"" 居中于屏幕中间,并填满整个屏幕。

我正在尝试实现从一个视图到另一个视图的水平滚动,这样我基本上一次只能在屏幕上看到一个视图。

这是我目前正在使用的代码

<HorizontalScrollView android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:fillViewport="true"
      android:scrollbars="none">
  <RelativeLayout android:id="@+id/GameBg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
     <ImageView  android:id="@+id/GameImageContainer3"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:scaleType="fitCenter"
      android:layout_toRightOf="@+id/GameImageContainer2"
      />
     <ImageView  android:id="@+id/GameImageContainer2"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:scaleType="fitCenter"
      android:layout_toRightOf="@+id/GameImageContainer1"
      /> 
     <ImageView  android:id="@+id/GameImageContainer1"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:scaleType="fitCenter"
      />
  </RelativeLayout>
</HorizontalScrollView>

我目前得到的是三个彼此相邻的图像——但有时它们占据的空间不到整个屏幕。我希望左右填充都是正确的,这样我一次只能看到一个图像。

有任何想法吗?

4

2 回答 2

0

尝试使用 ViewFlipper

http://www.androidpeople.com/android-viewflipper-example/

于 2011-02-02T14:19:13.020 回答
0

您是否尝试过Gallery Widget。这似乎是您正在寻找的东西。请务必查看图库教程

于 2010-10-03T18:14:49.750 回答