8

我正在制作一个应用程序,我希望从右到左填充gridview“以将其用于从右到左的语言”,我试图将gridView重力设置为右,但它没有用......我的gridview 布局如下。

提前致谢

<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>
4

6 回答 6

5

我认为您最好的猜测是从GridView 源代码复制代码并将测量/布局更改为从右到左使用。

更新:视图的布局方向仅在 API 级别 17 (4.2) 中引入。如果您比较4.24.1中的 GridView.java ,您可以看到,例如在方法makeRow()中,layoutDirection 从 4.2 开始就被考虑在内,所以应该可以工作!

您是否尝试android:layoutDirection="rtl"在 API 级别 17 上执行您的代码?

于 2013-08-28T13:07:24.923 回答
4

我认为 GridView 在设计时并没有考虑到语言。它更多的是用于排列缩略图的视觉组件。

您可以通过修改适配器并让它反转每行每个项目的顺序来解决该问题。但是,您需要告诉适配器每行的项目数量才能使其正常工作。

最重要的是,如果最后一行的项目比可能的少,那么您需要引入空的虚拟项目来填充左侧。

于 2012-07-10T15:22:37.820 回答
3

你可以试试这个。让布局文件中的 GridView 具有以下属性

android:layoutAnimation="@anim/layout_grid_right_to_left"

创建一个anim文件夹,在其中添加layout_grid_right_to_left.xml内容

<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" />

还要fade.xml在同一个anim文件夹中添加内容

<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" />

这些仅供您参考。请随意添加/删除适合您的需要/要求的属性。

于 2013-08-29T09:08:41.907 回答
2

你可以试试

android:layoutDirection="rtl"

它通常用于文本,我不知道对 gridView 有什么影响。(参考

另一件要尝试的是

android:stackFromBottom="true"

但是,如果您需要从上到下和从右到左(ref)订购物品,它将不起作用

于 2013-08-22T13:23:40.507 回答
2

您可以为您的 gridview 及其 XML 中的所有项目尝试此操作:

 android:rotationY="180"

您也可以使用android:layoutDirection="rtl". 它可能会解决您的问题。

于 2014-09-15T07:06:01.507 回答
1

有一种愚蠢的方法可以做到这一点,但它工作得很好。

只需android:ScaleX=-1在 gridview 和您的项目容器中制作(您的网格视图单元格的自定义视图),因此您的布局从右到左开始!

希望这有帮助

于 2015-04-27T11:08:08.050 回答