• ugui在运行时改变RectTransform的大小


    http://blog.csdn.net/BeiFuDeNvWang/article/details/50838266

    在代码中动态改变RectTransform大小的方法如下所示:

    1:直接对sizeDelta属性进行赋值,其中X和Y可以对应理解成width和height。sizeDelta的具体含义:若achors是一个点的话则代表宽高,否则为到锚点的距离

    var rt = gameObject.GetComponent<RectTransform>();
    rt.sizeDelta = new Vector2(100, 30);

    2:使用SetSizeWithCurrentAnchors函数来进行设定,其中Horizontal和Vertical分别对应宽和高。此函数受当前锚点和中心点的影响。

    var rt = gameObject.GetComponent<RectTransform>();
    rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
    rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 30);

    3:使用SetInsetAndSizeFromParentEdge函数来进行设定。此函数不受锚点和中心的影响,其中第一个参数代表对齐方式,第二个参数为距离边界的距离,第三个参数为宽度。

    var rt = gameObject.GetComponent<RectTransform>();
    rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, 100);
    rt.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, 30);


    在确定使用绝对位置的时候,推荐使用第三种方法。 
    参考文章:http://www.manew.com/thread-41633-1-1.html


  • 相关阅读:
    程序的编码问题
    man DMIDECODE
    Github熟悉一
    man uname
    第一轮铁大树洞APP开发冲刺(2)
    第九周学习进度
    第九周安卓开发学习总结(3)
    第一轮铁大树洞APP开发冲刺(1)
    第九周安卓开发学习总结(2)
    第九周安卓开发学习总结(1)
  • 原文地址:https://www.cnblogs.com/nafio/p/9137337.html
Copyright © 2020-2023  润新知