更改 GridView 的行为以使其水平滚动而不是垂直滚动 [英] Change the behaviour of a GridView to make it scroll horizontally rather than vertically

查看:20
本文介绍了更改 GridView 的行为以使其水平滚动而不是垂直滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个 UI 元素,就像 GridView 一样,我希望它具有完整的功能,但希望它可以水平滚动而不是垂直滚动.

I want to make a UI element like a GridView, I want it's complete functionality but want it to be horizontally scrollable rather than vertically.

水平滚动我的意思是它应该以这种方式构建,而不是放在 Horizo​​ntalScrollView 中.

By horizontal scroll I mean it should be built that way and not put in a HorizontalScrollView.

我将是 Custom GridView 将有固定数量的 rows4-5 并且 columns 应该根据 Adapter 中的项目数量可扩展.您可以将其视为与原生 GridView 所做的相反,但它应该保持功能.

My would be Custom GridView will have fixed number of rows say 4-5 and the columns should be extensible based on number of items in the Adapter. You can think of it as the opposite of what the native GridView does, yet it should maintain the functionality.

我已经查看了 Google 如何实现 GridView 的源代码,但我理解的很少,并且开始从头开始制作 View这似乎不是一个好主意,因为恐怕我无法像谷歌那样对内存优化做出公正的评价.

I have looked at the source code of how a GridView is implemented by Google, but I am able to understand very less and starting to make the View from scratch doesn't seem to be a good idea, since I am afraid I will not be able to do justice to memory optimization's the way Google did it.

我观察到 GridView 扩展了 AbsListView,所以我的问题是,它是 AbsListView 允许 GridView> 垂直滚动并从适配器添加项目,还是 GridView 增加了垂直滚动能力?我应该调整 GridView 还是 AbsListView?

I had observed that GridView extends AbsListView, so my question is, is it AbsListView which lets a GridView scroll vertically and add items from the adapter, or is it GridView which adds the vertical scrolling ability? Should I tweak GridView or AbsListView?

最好知道是否有一些东西已经在做我想做的事情?

It would be even better to know if there's something which already does what I want to do?

这已在 Android Honeycomb 3.1 及更高版本的原生图库和 YouTube 应用中实现.所以如果有人有想法,请详细说明.

This has already been implemented in native Gallery and YouTube app of Android Honeycomb 3.1 and above. So if anyone has an idea, please elaborate.

Honeycomb Gallery 应用快照:

Honeycomb YouTube 应用的快照:

推荐答案

API 11 中有 setRotation.您必须将 gridview 旋转 90 度,将子视图旋转 -90 度.

There is setRotation in API 11. You'll have to rotate the gridview by 90 degrees and child views by -90 degrees.

文档:http://developer.android.com/reference/android/view/View.html#setRotation(float)

在遵循 API 的视图上获得 3d 效果会很有用

To get a 3d effect on views following APIs would be useful

setCameraDistance(float) - 设置 z 轴距离(深度)

setCameraDistance(float) - set the z axis distance(depth)

setRotationX(float) - 设置水平轴角度

setRotationY(float) - 设置垂直轴角度

将相机距离设置为屏幕高度的一半.然后根据视图在屏幕上的位置设置rotationX.从左到右,旋转角度应该类似于 (20, 10, 0, -10, -20) .稍后您可以使用rotationY 角度来获得一些高度感知.

Set the camera distance to half of the screen height. Then set the rotationX based on the view's location on screen. The rotation angles should be something like (20, 10, 0, -10, -20) from left to right. Later you can play with rotationY angles to get some height perception.

在扩展的 GridView 覆盖的 layout 方法中进行所有设置.

Do all setting in extended GridView's overriden layout method.

@override
void layout(int t, int l, int r, int b) {
    super.layout(t, l, r, b);
    ...
    int columnStart = getFirstVisiblePosition()/no_of_columns;
    int columnEnd = getLastVisiblePosition()/no_of_columns;

    loop from 'columnStart' to 'columnEnd' 'no_of_colmns' times {
        // set the camera distance and rotationX to views
        // depending on the position of a view on screen.
    }
}

这篇关于更改 GridView 的行为以使其水平滚动而不是垂直滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆