Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start the GridView Elements from the right

I am making an app where i want the gridview to be filled from the right to the left "to use it for right to left languages", i tried to make the gridView gravity set to right but it didn't work ... my gridview layout is below.

Thanks in advance

<RelativeLayout
    android:id="@+id/grid_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/show_info"
    android:gravity="right" >

    <GridView
        android:id="@+id/channel_grid"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:columnWidth="90dp"
        android:gravity="right"
        android:horizontalSpacing="10dp"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth"
        android:verticalSpacing="10dp" >
    </GridView>
</RelativeLayout>
like image 573
Sara Avatar asked Jul 10 '12 15:07

Sara


2 Answers

I think your best guess is to copy the code from the GridView source and change the measuring/layouting to use right to left.

UPDATE: The layout direction for views was only introduced in API Level 17 (4.2). If you compare GridView.java in 4.2 and 4.1, you can see that for example in the method makeRow(), the layoutDirection is taken into account since 4.2, so that should work!

Did you try to execute your code with android:layoutDirection="rtl" on API Level 17 ?

like image 176
Jelle Avatar answered Nov 13 '22 10:11

Jelle


I don't think GridView was designed having languages in mind. It is more of a visual component for arranging thumbnail images.

You could solve that problem by modifying your adapter and letting it reverse the order of each item per row. However, you'd need to tell your adapter the amount of items per row for making that work.

On top of that if the last row has less items than possible, then you need to introduce empty dummy items for filling up the left.

like image 4
tiguchi Avatar answered Nov 13 '22 10:11

tiguchi