许多 GridView 一起放在一个relativelayout中

发布于 2024-10-13 19:16:58 字数 3160 浏览 6 评论 0原文

我开发了一个Android应用程序来解决“魔方”。首先将从立方体的每一面扫描立方体。颜色识别后,新的活动开始并在 2D 模型中显示结果。这在很多 GridView 中都是实现的。对于每一侧我都有一个 GridView。

现在我的问题是:我已将每个 Gridview 设置为可点击,但只有其中三个可点击。 有效的网格是第一个中间有白色面的网格,中间有蓝色面的网格和中间有黄色面的网格。所有其他网格都不可点击,但为什么呢?我需要它为每个 GridView 实现 OnItemClickListeners,以便在必要时纠正颜色。

我的 XML 文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">


     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewU"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:gravity="center"
     />

     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewF"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:focusable="true"
     android:gravity="center"
     android:layout_below="@id/gridviewU"
     />

     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewD"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:gravity="center"
     android:layout_below="@id/gridviewF"
     />

     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewB"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:gravity="center"
     android:layout_below="@id/gridviewU"
     /> 

     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewL"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:gravity="center"
     android:layout_below="@id/gridviewU"
     /> 

    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridviewR"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numColumns="auto_fit"
    android:verticalSpacing="5dp"
    android:horizontalSpacing="1dp"
    android:columnWidth="28dp"
    android:gravity="center"
    android:layout_below="@id/gridviewU"
    />     
</RelativeLayout>



谁能帮助我吗?谢谢...

[编辑] 我已经解决了我的问题。现在我使用 AbsoluteLayout 为每个 GridView 提供固定坐标。

I developing an Android App to solve the "Rubiks Cube". First the Cube will be scanned from each side of the Cube. After color recognition a new activity starts and show the result in a 2D-model. This is realized in much GridViews. For each side i have one GridView.

Now my problem: I've set each Gridview clickable but only three of them are clickable.
The Grids wich works are the first with the white facelet in the middle, the Grid with the blue facelet in the middle and the Grid with the yellow facelet in the middle. All the other Grids are not clickable, but why? I need it to implement the OnItemClickListeners for each GridView so if necessary to correct a color.

My XML File looks like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">


     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewU"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:gravity="center"
     />

     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewF"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:focusable="true"
     android:gravity="center"
     android:layout_below="@id/gridviewU"
     />

     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewD"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:gravity="center"
     android:layout_below="@id/gridviewF"
     />

     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewB"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:gravity="center"
     android:layout_below="@id/gridviewU"
     /> 

     <GridView xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gridviewL"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:numColumns="auto_fit"
     android:verticalSpacing="5dp"
     android:horizontalSpacing="1dp"
     android:columnWidth="28dp"
     android:gravity="center"
     android:layout_below="@id/gridviewU"
     /> 

    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gridviewR"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numColumns="auto_fit"
    android:verticalSpacing="5dp"
    android:horizontalSpacing="1dp"
    android:columnWidth="28dp"
    android:gravity="center"
    android:layout_below="@id/gridviewU"
    />     
</RelativeLayout>

Can anyone help me? Thanks...

[EDIT]
I've solved my problem. Now i use an AbsoluteLayout with fix coordinates for each GridView.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放飞的风筝 2024-10-20 19:16:58

问题解决了。请参阅上面的编辑行。

Problem is solved. See the EDIT-line above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文