GridLayout不能均匀地扩展元素 [英] GridLayout does not expand elements evenly

查看:69
本文介绍了GridLayout不能均匀地扩展元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GridView将屏幕分成六个相等的部分.问题是它在模拟器中正确显示,但是当我从电话查看它时,空间分布不均匀.是什么导致这种现象?

i am trying to use GridView to divide the screen into six equal pieces. The problem is that it displays properly in the emulator but when i view it from the phone then the space is distributed unevenly. What could cause this behavior?

我已经使用API​​ 21& API 22手机.

I have tested this with API 21 & API 22 phones.

仿真器与电话:

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.myapp.myapp.myapp.MainActivity"
    tools:showIn="@layout/activity_main">

        <GridLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:columnCount="2"
            android:rowCount="3"
            android:layout_centerInParent="false">

            <Button
                android:layout_column="0"
                android:layout_gravity="fill"
                android:layout_row="0"
                android:layout_columnWeight="1.0"
                android:layout_rowWeight="1.0"
                android:text="c0 | r0" />

            <Button
                android:layout_column="1"
                android:layout_gravity="fill"
                android:layout_row="0"
                android:layout_columnWeight="1.0"
                android:layout_rowWeight="1.0"
                android:text="c1 | r0" />

            <Button
                android:layout_column="0"
                android:layout_gravity="fill"
                android:layout_row="1"
                android:layout_columnWeight="1.0"
                android:layout_rowWeight="1.0"
                android:text="c0 | r1" />

            <Button
                android:layout_column="1"
                android:layout_gravity="fill"
                android:layout_row="1"
                android:layout_columnWeight="1.0"
                android:layout_rowWeight="1.0"
                android:layout_width="0dp"
                android:text="c1 | r1" />

            <Button
                android:layout_column="0"
                android:layout_gravity="fill"
                android:layout_row="2"
                android:layout_columnWeight="1.0"
                android:layout_rowWeight="1.0"
                android:text="c0 | r2" />

            <Button
                android:layout_column="1"
                android:layout_gravity="fill"
                android:layout_row="2"
                android:layout_columnWeight="1.0"
                android:layout_rowWeight="1.0"
                android:text="c1 | r2" />
        </GridLayout>

</RelativeLayout>

推荐答案

据我所知,布局权重仅适用于LinearLayout,但是您正在使用RelativeLayout.尝试切换它.

As far as I know, the layout weight works only with LinearLayout but you are using RelativeLayout. Try to switch it.

这篇关于GridLayout不能均匀地扩展元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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