Android:如何在布局中放置纯色矩形? [英] Android: How do I put a solid color rectangle in a Layout?

查看:300
本文介绍了Android:如何在布局中放置纯色矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以放大的RelativeLayout.我想在顶部添加一个横跨布局宽度的纯色矩形.我尝试将以下内容放入我的xml中:

I have a RelativeLayout that inflates just fine. I would like to add a solid color rectangle spanning the width of the layout at the top. I tried putting the following into my xml:

<view android:id="@+id/top_alert"
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_above="@+id/orders_gridview"
    android:layout_alignParentTop="true"
    android:background="@color/table_request_assistance"
    android:visibility="visible"/>

现在,当我尝试为自己的布局充气时,我在LayoutInflater.createViewFromTag(第715行)处得到了NullPointerException:

Now, when I try to inflate my Layout I get a NullPointerException at LayoutInflater.createViewFromTag (line 715):

if (name.equals(TAG_1995)) {

name设置得较早:

if (name.equals("view")) {
    name = attrs.getAttributeValue(null, "class");
}

很明显,没有"class"属性.如何添加呢?我在 http://schemas.android.com/apk/res/android中找不到任何关闭的内容.我应该添加它吗?这是执行此操作的标准方法吗?看来这应该是世界上最简单的事情.

Evidently there is no "class" attribute. How do I add that? I can't find anything close in http://schemas.android.com/apk/res/android. Should I add it? Is this the standard way to do this? It seems like it should be the simplest thing in the world.

推荐答案

类区分大小写-在这种情况下,您使用的是

Classes are case sensitive - in this case, you are using the View class and therefore it needs to be exactly View in your XML.

这篇关于Android:如何在布局中放置纯色矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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