下课睡觉 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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。