【发布时间】:2017-07-28 03:20:38
【问题描述】:
我正在尝试使用 8 个不同的框(2 列 * 4 行)制作网格布局。不幸的是,每当我尝试加载图像时,它都会出错并加载我图像的升级版本。这是我的代码。必须注意,当我只是加载一些文字时,它工作得很好。
首先它看起来像这样: Without background image
使用以下代码:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:background="@drawable/garage">
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@android:color/background_dark" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@android:color/background_light" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@android:color/holo_green_dark" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@android:color/holo_orange_dark" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@android:color/holo_purple" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@android:color/holo_orange_light" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@android:color/holo_red_light" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@android:color/darker_gray" />
</GridLayout>
在我尝试在其中一个单元格中添加背景图像后,我得到的是:Only one cell that takes up more space than the whole screen as it looks
有以下代码:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:background="@drawable/garage">
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:background="@drawable/spaceshuttle1" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1" />
<TextView
android:layout_columnWeight="1"
android:layout_rowWeight="1" />
</GridLayout>
我该怎么做才能让图像留在它的单元格中?
【问题讨论】: