网格布局列超越其边界 [英] GridLayout column is going beyond its bounds

查看:193
本文介绍了网格布局列超越其边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个网格状的形式,类似的官方Android开发者博客的例子。

I'm trying to make a grid-like form, similar to the example on the official Android Developers blog.

下面是我的布局:

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

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="48dp"
        android:layout_marginRight="48dp"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:columnCount="2"
        android:rowCount="2">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_gravity="end"
            android:layout_row="0"
            android:text="Send"
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="24sp" />

        <Spinner
            android:id="@+id/send_currency"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_row="0" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_gravity="end"
            android:layout_row="1"
            android:text="to"
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="24sp" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_row="1"
            android:hint="username"
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="24sp" />
    </GridLayout>
</LinearLayout>

我左边的列(静态文本,右对齐)工作正常。它对齐文本向右,宽度依赖于最广泛的一行。

My left column (static text, right-aligned) is working fine. It aligns the text to the right, and the width is dependent on the widest row.

不过,右栏似乎绘制网格布局的边界之外的方法。

However, the right column seems to be drawing way outside of the bounds of the GridLayout.

在那张照片中,蓝色的盒子是网格布局的边界。你已经可以看到顶部的绿条的问题。右侧是应该在网格布局(如左侧)的界限被停止,但由于某些原因,它会过去的方式吧。

In that picture, the blue box is the bounds of the GridLayout. You can already see the problem in the green bar at the top. The right side is supposed to be stopping at the bounds of the GridLayout (like the left side is), but for some reason it's going way past it.

在该图中的蓝色方块是EditText上的边界(它设置为wrap_content)。然而,水绿色的盒子是在它的允许扩大范围。当我输入大量的字符集的EditText的,它会过去的网格布局的边界,甚至过去在手机屏幕的边缘!

The blue box in that picture is the bounds of the EditText (it's set to wrap_content). However, the aqua-colored box is the bounds in which it's allowed to expand. When I type lots of characters into the EditText, it goes past the GridLayout's bounds, and even past the edge of the phone screen!

这是在网格布局中的错误?还是我失去了一些东西?

Is this a bug in GridLayout? Or am I missing something?

推荐答案

这是网​​格布局正常的行为。

幸运的是,网​​格布局新版本,这与API添加21这一事实谢谢,你可以让网​​格布局可容纳孩子的宽度或高度根据它的方位。

Fortunately, there is a new version of GridLayout, which was added with API 21. Thanks of that fact, you can make GridLayout accomodates children to its either width or height according as its orientation.

要知道详细看文档 ,尤其是在的类概述 - >多余的空间分布的。

要充分利用新的网​​格布局,你需要的将其添加为支持库 XML 是你应该使用:

To make use of new GridLayout, you need to add it as support library and in xmls you should use:

<android.support.v7.widget.GridLayout ... >

而不是

<GridLayout ... > 

这篇关于网格布局列超越其边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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