【问题标题】:Android setting up dimension get Error:(100, 33) String types not allowed (at 'layout_height' with value 'wrap_content')Android设置维度得到错误:(100、33)不允许字符串类型(在'layout_height',值为'wrap_content')
【发布时间】:2017-03-12 23:21:09
【问题描述】:

我设置了一个资源维度:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="font_size">36sp</dimen>
    <dimen name="layout_height">wrap_content</dimen>
    <dimen name="layout_width">wrap_content</dimen>
</resources>

并使用以下内容引用它:

<Button
    android:layout_columnWeight="1"
    android:background="@drawable/button_style"
    android:id="@id/btnAC"
    android:layout_width="@dimen/layout_width"
    android:layout_height="@dimen/layout_height"
    android:text="@string/valAC"
    android:textColor="@color/white"
    android:textSize="@dimen/font_size" />

但在尝试运行应用程序时出现以下错误。 错误:(100, 33) 不允许使用字符串类型(在 'layout_height' 处,值为 'wrap_content')。

【问题讨论】:

标签: android android-layout compiler-errors


【解决方案1】:

wrap_content 不支持作为资源维度。只需在布局文件中使用 wrap_content,而不是 @dimen/layout_height 和 @dimen/layout_width。

【讨论】:

  • 会使用 -2dp 代替 wrap_content 吗?我使用它的主要目的是我尝试测试的许多按钮。所以,我一直在改变 layout_height 和 layout_width 的值。我不想更改所有按钮中的值,而是更改一次。
  • 我不确定。试试看。根据这个问题,它可能会起作用stackoverflow.com/questions/17525957/… 您也可以尝试在为按钮创建自定义样式时是否支持 wrap_content。这也可以更轻松地一次将更改应用到您的按钮。
  • 通读链接并找到有效的解决方案。谢谢。
【解决方案2】:

你不能在资源文件中添加 wrap_content

你应该这样做

<Button
    android:layout_columnWeight="1"
    android:background="@drawable/button_style"
    android:id="@id/btnAC"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/valAC"
    android:textColor="@color/white"
    android:textSize="@dimen/font_size" />

【讨论】:

    猜你喜欢
    • 2017-04-03
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多