首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >呈现android布局时出错。未知宽度异常错误

呈现android布局时出错。未知宽度异常错误
EN

Stack Overflow用户
提问于 2017-08-17 15:16:48
回答 2查看 45关注 0票数 1
代码语言:javascript
运行
复制
java.lang.IllegalArgumentException: width and height must be > 0
        at android.graphics.Bitmap.createBitmap(Bitmap.java:877)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:856)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:823)
        at uk.co.daentech.circulardemo.widgets.ProgressBar.onDraw_Original(ProgressBar.java:62)
        at uk.co.daentech.circulardemo.widgets.ProgressBar.onDraw(ProgressBar.java)

Layout_cell.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"

    android:weightSum="1">
    <!-- android:background="@drawable/orangeback"-->

    <TextView
        android:id="@+id/main.weather_icon"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:textAlignment="center"
        android:textColor="#000000"
        android:textSize="52sp"
        tools:text="Icon"/>

    <TextView
        android:id="@+id/main.temperature"
        android:layout_width="57dp"
        android:layout_height="match_parent"
        android:layout_weight="1.34"
        android:gravity="center"
        android:textAlignment="center"
        android:textColor="@android:color/white"
        android:textSize="50sp"
        tools:text="20" />

    <uk.co.daentech.circulardemo.widgets.ProgressCircle
          android:id="@+id/progress_circle"
          android:layout_width="166dp"
          android:layout_height="148dp"
          android:layout_margin="30dp"
          android:textSize="80sp"
          android:textColor="#BBD452"
          app:progressColor="#BBD452"
          app:incompleteProgressColor="#D4D4D4"
          app:strokeWidth="15dp"

          />

   <uk.co.daentech.circulardemo.widgets.ProgressBar
          android:id="@+id/progress_bar"
          android:layout_margin="20dp"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0.10"
          />

      <uk.co.daentech.circulardemo.widgets.ProgressBar
          android:id="@+id/progress_bar2"
          android:layout_margin="20dp"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="0.11"
          />

      <GridLayout
          android:orientation="horizontal"
          android:layout_width="410dp"
          android:layout_height="match_parent"
          android:gravity="center"
          >


          <uk.co.daentech.circulardemo.widgets.ProgressCircle
          android:id="@+id/progress_circle2"
              android:layout_width="105dp"
              android:layout_height="95dp"
              android:textSize="36sp"
              android:textColor="@android:color/holo_orange_light"
              app:progressColor="@android:color/holo_orange_light"
              app:incompleteProgressColor="#D4D4D4"
              app:strokeWidth="10dp"
              android:layout_marginTop="90dp"
              android:layout_row="0"
              android:layout_column="0"
              android:layout_marginLeft="45dp" />

          <uk.co.daentech.circulardemo.widgets.ProgressCircle
              android:id="@+id/progress_circle3"
              android:layout_width="105dp"
              android:layout_height="95dp"
              android:textSize="36sp"
              android:textColor="@android:color/holo_red_light"
              app:progressColor="@android:color/holo_red_light"
              app:incompleteProgressColor="#D4D4D4"
              app:strokeWidth="10dp"
              android:layout_row="0"
              android:layout_column="2"
              android:layout_marginTop="90dp"
              android:elevation="0dp"
              android:layout_margin="-2dp" />

          <uk.co.daentech.circulardemo.widgets.ProgressCircle
          android:id="@+id/progress_circle4"
              android:layout_width="105dp"
              android:layout_height="95dp"
              android:textSize="36sp"
          android:textColor="@android:color/holo_purple"
          app:progressColor="@android:color/holo_purple"
          app:incompleteProgressColor="#D4D4D4"
          app:strokeWidth="10dp"
              android:layout_marginTop="30dp"
              android:layout_margin="5dp"
              android:layout_row="0"
              android:layout_column="1"
              />


      </GridLayout>

    </LinearLayout>

由于非法的参数异常,我在布局上出现了奇怪的错误。我真的不明白出了什么问题。请指点。当我使用>0检查时,我的宽度和高度总是Logcat。此错误不会阻止编译,我可以成功构建代码。但是它不允许我看到我的Layout_cell.xml文件的设计格式。

EN

回答 2

Stack Overflow用户

发布于 2017-08-17 16:02:45

将所有uk.co.daentech.circulardemo.widgets.ProgressBarlayout_widthlayout_height更改为常量维度。

例如:

代码语言:javascript
运行
复制
<uk.co.daentech.circulardemo.widgets.ProgressBar
      android:id="@+id/progress_bar"
      android:layout_margin="20dp"
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_weight="0.10"/>
票数 0
EN

Stack Overflow用户

发布于 2017-08-18 08:48:23

在设置常量layout_width和高度后,Ia km仍然得到相同的误差。我观察到

代码语言:javascript
运行
复制
>   <uk.co.daentech.circulardemo.widgets.ProgressBar
>           android:id="@+id/progress_bar"
>           android:layout_margin="20dp"
>           android:layout_width="10dp"
>           android:layout_height="30dp"
>           android:layout_weight="0.10"
>           />
> 
>       <uk.co.daentech.circulardemo.widgets.ProgressBar
>           android:id="@+id/progress_bar2"
>           android:layout_margin="20dp"
>           android:layout_width="10dp"
>           android:layout_height="30dp"
>           android:layout_weight="0.11"
>           />

消除了错误。

我有一个独立的代码来设计Progressbar。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45738984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档