在视图之间滚动

发布于 2024-09-26 01:49:12 字数 1405 浏览 2 评论 0原文

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

我有三个彼此相邻的 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>

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

有什么想法吗?

I'm currently working on a game for android.

I have three ImageView's next to each other, they're positioned next to each other using the "android:layout_toRightOf". The views are located within a RelativeLayout tag. Each of these views are centered into the middle of the screen using "android:scaleType="fitCenter"" and they fill the entire screen.

I'm attempting to implement a horizontal scroll from one view to another so that I basically get one view on my screen at a time.

Here is the code that I'm currently using

<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>

What I'm currently getting is three images next to each other -- but sometimes they take up less then an entire screen. I want both the left and right padding to be correct, so that I can only see one image at a time.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心头的小情儿 2024-10-03 01:49:12

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

Have you tried the Gallery Widget. It seems to be what you are looking for. Be sure to also check out the Gallery tutorial.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文