Start GridView Elements on the Right

I am creating an application in which I want the gridview to be filled from right to left, "to use it for right-handed languages," I tried to make the grid grid power to the right, but that did not work ... my grid layout is lower.

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> 
+8
android gridview
source share
6 answers

I think that itโ€™s best for you to copy the code from the GridView source and change the dimension / layout to use from right to left.

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

Have you tried to execute your code with android:layoutDirection="rtl" at API level 17?

+5
source share

I don't think GridView was designed with language in mind. It is rather a visual component for creating thumbnails.

You can solve this problem by changing your adapter and letting it change the order of each item in a row. However, you need to tell your adapter the number of elements per line to do this job.

In addition, if the last line has fewer elements than possible, then you need to enter empty dummy elements to fill the left.

+4
source share

You can try this. Your gridview has the following attribute in your layout file

 android:layoutAnimation="@anim/layout_grid_right_to_left" 

Create an anim folder in which you add layout_grid_right_to_left.xml with kotents

 <gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android" android:columnDelay="0.5" android:directionPriority="row" android:direction="right_to_left" android:animation="@anim/fade" /> 

Also add fade.xml to the same anim folder with the contents

 <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="@android:integer/config_longAnimTime" /> 

This is for your reference only. Feel free to add / remove attributes matching your requirements / requirements.

+3
source share

You can try

 android:layoutDirection="rtl" 

This is usually text, and I donโ€™t know what affects gridView. ( ref )

Another thing to try:

 android:stackFromBottom="true" 

But this will not work if you need to order items from top to bottom and from right to left (ref)

+2
source share

You can try this for gridview and all its elements in XML:

  android:rotationY="180" 

You can also use android:layoutDirection="rtl" . This may solve your problem.

+2
source share

There is a dumb way to do this, but it works great.

just make android:ScaleX=-1 in the gridview and in the element container (your custom view for the grid cells) so that your layout starts from right to left!

hope this help

+1
source share

All Articles