专栏名称: 安卓开发精选
伯乐在线旗下账号,分享安卓应用相关内容,包括:安卓应用开发、设计和动态等。
目录
相关文章推荐
复利大王  ·  好牛的幼儿园 ·  9 小时前  
复利大王  ·  不讲武德!中x银行? ·  9 小时前  
鸿洋  ·  务必立即拿下软考证(政策红利) ·  昨天  
复利大王  ·  520怀孕事件? ·  昨天  
51好读  ›  专栏  ›  安卓开发精选

那些你应该知道却不一定知道的 — View坐标分析汇总

安卓开发精选  · 公众号  · android  · 2016-08-24 08:07

正文

请到「今天看啥」查看全文


. getHeight ();

}

});


或者


@Override

public void onWindowFocusChanged ( boolean hasFocus ) {

super . onWindowFocusChanged ( hasFocus );

//此处可以正常获取width、height等

}


三.计算


现在对坐标系是咋样的,我们已经了解了。


对啥时候获取,以及获取后是否需要纠正得到正确的Y,我们也已经分析了。


下面就来说说本文的重头戏 ——— 坐标的计算。


(之所以说是重头戏,是因为我们之前得到的都是一个点的正确坐标,现在我们需要做的是在得到多个正确坐标后,进行正确的计算,这样我们才能实现滑动这样炫酷的效果`(∩_∩)′)


首先我们需要建立一个概念


在Android的坐标系中,原点在屏幕左上角,向右x为正,向下y为正。



(为了好计算,图片中的坐标单位是px)


(下面就以这个为例,我们要将View从原点移动到(200,400)的位置,即B点与C点重合)


想实现View移动大致有这几种方式(代码见下面)



XML文件


xml version = "1.0" encoding = "utf-8" ?>

LinearLayout xmlns : android = "http://schemas.android.com/apk/res/android"

xmlns : tools = "http://schemas.android.com/tools"

android : layout_width = "match_parent"

android : layout_height = "match_parent"

tools : context = ".MainActivity" >

LinearLayout

android : id = "@+id/ly"

android : background = "#EFAA88"

android : layout_centerInParent = "true"

android : layout_width = "300px"

android : layout_height = "500px" >

mr_immortalz . com . testlocation . TestTextView

android : background = "#aabbcc"

android : id = "@+id/tv"

android : text = "你好"

android : layout_width = "100px"

android : layout_height =







请到「今天看啥」查看全文