Android:创建可滚动布局

发布于 2024-08-31 07:33:38 字数 558 浏览 7 评论 0原文

我正在尝试在 Android 中创建一个“可滚动”布局。不过,即使使用developers.android.com,我现在也感觉有点失落。我对 Java 有点陌生,但还没有那么严重,以至于我觉得我应该遇到这些问题——对于 Android 来说,现在更大的问题是。

我尝试创建的布局应该以“网格”的形式滚动。我认为我正在寻找的是图库视图,但我现在真的不知道如何实现它。我希望它“捕捉”到框架中心,就像在实际的图库应用程序中一样。

本质上,如果我有一个包含 9 张照片的照片库,我的想法是以 3x3 的方式在它们之间上下和左右滚动。不需要动态调整,或类似的东西,我只想要一个可以滚动的网格。

我也不要求任何人给我明确的代码——我正在努力学习,而不是任何事情。但是,为我指明正确的方向以获取有用的布局编程资源将不胜感激,并且确认它是否是我正在寻找的图库视图也将非常有帮助。

编辑:为了澄清,目标是一次在屏幕上显示一个项目。如果您在一项和下一项之间滚动,则前一项会离开屏幕,新一项会卡入到位。因此,如果它是一个照片库,网格上的每个点都会大约占据整个屏幕大小,并且当您从任一方向滑到下一张照片时,网格上的每个点都会被抛出可视区域。 (照片仅供参考)

I'm trying to create a "scrollable" layout in Android. Even using developers.android.com, though, I feel a little bit lost at the moment. I'm somewhat new to Java, but not so much that I feel I should be having these issues--being new to Android is the bigger problem right now.

The layout I'm trying to create should scroll in a sort of a "grid". I THINK what I'm looking for is the Gallery view, but I'm really lost as to how to implement it at the moment. I want it to "snap" to center the frame, like in the actual Gallery application.

Essentially, if I had a photo gallery of 9 pictures, the idea is to scroll between them up/down AND side to side, in a 3x3 manner. Doesn't need to dynamically adjust, or anything like that, I just want a grid I can scroll through.

I'm also not asking for anyone to give me explicit code for it--I'm trying to learn, more than anything. But pointing me in the right direction for helpful layout programming resources would be greatly appreciated, and confirming if it's a Gallery view I'm looking for would also be really helpful.

EDIT: To clarify, the goal is to have ONE item on screen at a time. If you scroll between one item and the next, the previous one leaves the screen, and the new one snaps into place. So if it were a photo gallery, each spot on the grid would take up the entire screen size, approximately, and would be flung out of the viewable area when you slide across to the next photo, in either direction. (Photos are just an example for illustration purposes)

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

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

发布评论

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

评论(3

停滞 2024-09-07 07:33:38

这个页面很好地总结了不同的内置布局对象。根据您的描述, GridView 或可能是 TableLayout 可能有效。 GalleryView 看起来只是水平的。

This page gives a good summary of the different built in layout objects. From your description a GridView or possibly a TableLayout might work. GalleryView looks to be horizontal only.

魄砕の薆 2024-09-07 07:33:38

我相信 GridView 就是您正在寻找的。这是一个教程: http://developer.android.com/resources/教程/views/hello-gridview.html

I believe GridView is what you're looking for. Here's a tutorial: http://developer.android.com/resources/tutorials/views/hello-gridview.html

彩扇题诗 2024-09-07 07:33:38

您应该查看 ViewPager widget,可在 Android 兼容包中获取。我花了很长时间试图让 Gallery 小部件正常运行,但最终选择了返回 ImageView 对象的 ViewPager。就像魅力一样。

You should check out the ViewPager widget, which is available in the Android compatibility package. I spent a loooong time trying to get the Gallery widget to behave properly, but finally settled on a ViewPager which returned ImageView objects instead. Works like a charm.

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