更改GridView的行为以使其水平滚动而不是垂直滚动

Ari*_*eem 5 android android-custom-view android-listview android-gridview android-view

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

通过水平滚动我的意思是它应该以这种方式构建而不是放入HorizontalScrollView.

Custom GridView将会有固定数量的rows发言权4-5,而且columns应该extensible基于该项目的数量Adapter.您可以将其视为本机GridView所做的相反,但它应该保持功能.

我已经查看GridView了Google 如何实现的源代码,但是我能够理解得非常少,并且开始View从头开始并不是一个好主意,因为我担心我将无法按照谷歌的方式做事记忆优化.

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

知道是否已经做了我想做的事情会更好吗?

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

Honeycomb Gallery应用程序的快照:

在此输入图像描述

Honeycomb YouTube应用程序的快照:

在此输入图像描述

Ron*_*nie 11

setRotation在API 11.你必须-90度旋转,90度和儿童享有gridview的.

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

更新:

为了对API后面的视图产生3d效果会很有用

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

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

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

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

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

@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.
    }
}
Run Code Online (Sandbox Code Playgroud)