从右到左添加android gridview项目

从右到左添加android gridview项目,android,gridview,layout,Android,Gridview,Layout,我想让我的gridview从右向左添加项目 我的意思是这样的: 3 2 1 654 因此,我在mymain.xml中的gridview中添加了android:rotationY=“180” <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height=&

我想让我的gridview从右向左添加项目

我的意思是这样的:

3 2 1

654

因此,我在my
main.xml中的gridview中添加了
android:rotationY=“180”

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical" >
<GridView
    android:id="@+id/gridview"
    android:rotationY="180"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="right"
    android:columnWidth="90dp"
    android:gravity="right"
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth"
    android:verticalSpacing="10dp" />

  </LinearLayout>

但是它不起作用,我该怎么做才能使它起作用呢?

您应该将
android:rotationY=“180”
也添加到item.xml中

您可以编辑grid view的“适配器”,如下所示:

final Object object;
//move element at index 0 to index 2
if(position % 3 == 0 && items.size() > position +2){
    object = items.get(position + 2);
}
//move element at index 2 to index 0
else if(position % 3 == 2){
    object = items.get(position - 2);
}
//the element at index 1 still at index 1 (do nothing)
注意:如果在适配器中使用“onClickListener”而不是在网格视图中使用“onItemClickListener”,这将非常有效。或者,您可以使用相同的公式正确获取选定位置。;)


希望这能帮助你=D

谢谢你,哈米德,但正如你所看到的那样,将其添加到我的线性布局中,是否也需要将其添加到我的ImageView?不,就是这样,但问题是你的图像视图,我使用它,它对我有效,但如果可以的话,我使用文本视图代替图像视图,使用文本视图而不是图像视图,并将@drawable/folder_图标设置为该视图的背景。希望这对你有帮助。它对我不起作用,你能给我举个例子吗?
final Object object;
//move element at index 0 to index 2
if(position % 3 == 0 && items.size() > position +2){
    object = items.get(position + 2);
}
//move element at index 2 to index 0
else if(position % 3 == 2){
    object = items.get(position - 2);
}
//the element at index 1 still at index 1 (do nothing)