您的位置:首页 > 移动开发 > Android开发

android布局属性

2015-06-05 14:57 447 查看
1、获取组件的宽高

View view=LayoutInflater.from(context).inflate(R.layout.linerlayout, null);
        LinearLayout lineraLayout=(LinearLayout) view.findViewById(R.id.layout);
        lineraLayout.measure(0, 0);
        int width=lineraLayout.getMeasuredWidth(); //获取组件的宽度
        int height=lineraLayout.getMeasuredHeight();//获取组件的高度


2、获取该按钮相对于手机屏幕的位置坐标

View viewLayout=LayoutInflater.from(context).inflate(R.layout.linerlayout, null);
        View viewBtn=viewLayout.findViewById(R.id.button);

        //数组长度必须为2
        int[] locations=new int[2];
        viewBtn.getLocationOnScreen(locations);
        int x=locations[0]; //获取组件当前位置的横坐标
        int y=locations[1]; //获取组件当前位置的纵坐标
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: