64位指针膨胀 java_java – 空指针异常,当在膨胀的布局上调用测量时

所以我有一个单独的文件的布局,所以我膨胀。然后我在我的布局中更改我的文本视图和图像,并调用度量,但是当我尝试测量布局时,我会得到一个空指针。我不能为了我的生活找出为什么这是。我试图最终将布局转换为位图。

View inflatedView = ((Activity)getContext()).getLayoutInflater().inflate(R.layout.my_layout, null);

inflatedView.measure(getWidth(), getHeight());

inflatedView.layout(0, 0, inflatedView.getMeasuredWidth(),inflatedView.getMeasuredHeight());

Bitmap viewAsImage = Bitmap.createBitmap(inflatedView.getWidth(), inflatedView.getHeight(), Bitmap.Config.ARGB_8888);

Canvas viewCanvas = new Canvas(viewAsImage);

这是XML

android:layout_width="fill_parent"

android:layout_height="wrap_content" android:layout_gravity="bottom"

android:id="@+id/my_layout"

android:background="@color/transparent_black">

android:layout_width="48dip" android:layout_height="48dip"

android:layout_centerVertical="true" android:layout_alignParentLeft="true"

android:scaleType="fitXY" android:maxWidth="48dip" android:maxHeight="48dip"

android:padding="5dip" />

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginRight="20dip" android:src="@drawable/arrow"

android:layout_centerVertical="true" android:scaleType="fitXY"

android:maxWidth="48dip" android:maxHeight="48dip"

android:layout_alignParentRight="true" />

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_toRightOf="@id/image_left"

android:layout_toLeftOf="@id/image_right" android:id="@+id/some_name"

android:maxLines="1" android:ellipsize="end" android:textSize="20sp"

android:textColor="@color/white"

android:layout_centerVertical="true"

android:textStyle="normal" />

在measure()行,它抛出一个空指针,我已经验证了getWidth和getHeight给出合法值。

有任何想法吗?

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值