下课睡觉 2017-07-19 09:34 采纳率: 16.7%
浏览 1602
已采纳

android MessureSpec.Mode 什么时候是UNSPECIFIED?

以前累积的知识,都知道UNSPECIFIED这种模式很少出现,一般都是系统里面出现的。但是最近我自定义VIew的时候就遇到了,不知道如何解决.

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:orientation="horizontal">


    <MyTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/colorAccent"
        android:gravity="center"
        android:text="英雄"
        android:textSize="20sp" />

    <MyTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/colorAccent"
        android:gravity="center"
        android:text="击杀"
        android:textSize="20sp" />

    <MyTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@color/colorAccent"
        android:gravity="center"
        android:text="阵亡"
        android:textSize="20sp" />

</LinearLayout>

这一个LinearLayout布局,我想在我的自定义布局中,放到指定的位置,然后通过

 LayoutInflater.from(this).inflate(R.layout.head,null)

来加载这个布局,赋值给这个变量View view,然后在调用addView(view),将这个布局加入到我的自定义View中去。

在我的自定义布局onMeasure()方法中,调用这个view.measure()来测量宽高,可是发现出来的效果并不是我想的那样,三个TextView并没有平分LinearLayout的宽度,然后调试了下发现,这些TextView的onMeasure方法中传入的MeasureSpec.Mode都是UNSPECIFIED,这是为啥啊?

  • 写回答

3条回答

  • 下课睡觉 2017-08-03 08:18
    关注

    不好意思,这个值我也不知道啥时候碰到了,改了下代码发现又没有了。。。。。应该是我当时写的时候哪里出了点问题,现在好了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题