在视图之间滚动
我目前正在开发一款安卓游戏。
我有三个彼此相邻的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过图库小部件。这似乎就是您正在寻找的东西。请务必查看图库教程。
Have you tried the Gallery Widget. It seems to be what you are looking for. Be sure to also check out the Gallery tutorial.
尝试使用 ViewFlipper
http://www.androidpeople.com/android-viewflipper-example/
Try using a ViewFlipper
http://www.androidpeople.com/android-viewflipper-example/