机器人,水平和垂直滚动的网格布局 [英] Android, Horizontal and Vertical Scroll for GridLayout

查看:213
本文介绍了机器人,水平和垂直滚动的网格布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法得到一个GridLayout的水平滚动。

I'm having trouble getting a GridLayout to scroll horizontally.

我发现了一个类似的问题网格布局+滚动型。我试过这种方法,但没有奏效。

I found a similar question Gridlayout + ScrollView. I tried that method, but it didn't work.

这削减了许多表(因为它本来是要显示所有表从1到20)。

It cuts out many tables (because it was supposed to go display all tables from 1 to 20).

下面是XML文件

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:padding="16dp" >

            <android.support.v7.widget.GridLayout
                android:id="@+id/table_mapGrid"
                android:layout_width="250dp"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </ScrollView>

    <include layout="@layout/cell_list_loading" />

    <TextView
        android:id="@+id/table_errorView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="20dp"
        android:text="@string/message_error_connection"
        android:visibility="invisible" />

</FrameLayout>

我想有动态内容显示,与表之间的空的空间变化的行和列的数量可能。 这个我已经完成了,但问题是当GridLayout的宽度大于它的容器的,我想,使用水平滚动来解决,但它似乎并没有工作...

I want to have dynamic content displayed, varying the number of columns and rows possibly with empty spaces between tables. This I have accomplished, but the problem is when the width of the GridLayout becomes greater than its container's, I wanted to solve that using horizontal scroll, but it doesn't seem to work...

任何建议?

推荐答案

嗯,我找到了解决办法

这似乎是Android的滚动型可以作为一个VerticalScrollView且只有(名字不那么直观Horizo​​ntalScrollView)。

It seems like the android ScrollView works as a VerticalScrollView and only that (the name is not so intuitive as HorizontalScrollView).

因此​​,为了使一些滚动垂直和水平方向,你需要嵌套(垂直)滚动型内Horizo​​ntalScrollView,或其他方式,像这样

So to make something scrollable vertically and horizontally, you need to nest a (Vertical)ScrollView inside a HorizontalScrollView, or the other way around, like this

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

            <!-- Your content here -->

     </HorizontalScrollView>
</ScrollView>

这篇关于机器人,水平和垂直滚动的网格布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆