获取组件坐标系

简介: java代码: package com.example.test1; import android.app.Activity; import android.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="button" />

    <TextView
        android:id="@+id/l"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text"
        android:layout_gravity="center" />

</LinearLayout>

java代码:

package com.example.test1;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    private TextView t = null;
    private Button button = null;
    int x;
    int y;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        t = (TextView)findViewById(R.id.l);
        button = (Button)findViewById(R.id.button);
        button.setOnClickListener(new buttonListener());
    }   
    //获取组件t的坐标
    public class buttonListener implements OnClickListener{

        public void onClick(View v)
        {
            int[] location = new int[2];
            t.getLocationOnScreen(location);
            x = location[0];
            y = location[1];
            System.out.println("x:"+x+"y:"+y);
            System.out.println("图片各个角Left:"+t.getLeft()+"Right:"+t.getRight()+"Top:"+t.getTop()+"Bottom:"+t.getBottom());
        }
    }
}

 

相关文章
|
Android开发 索引 容器
【Android 应用开发】Android 组件 位置坐标 属性 ( 组件位置属性 | 父容器坐标系坐标 | 窗口坐标系坐标 | 屏幕坐标系坐标 | 触摸坐标 )
【Android 应用开发】Android 组件 位置坐标 属性 ( 组件位置属性 | 父容器坐标系坐标 | 窗口坐标系坐标 | 屏幕坐标系坐标 | 触摸坐标 )
265 0
|
8月前
154Echarts - 平行坐标系(Prices and Earnings 2012)
154Echarts - 平行坐标系(Prices and Earnings 2012)
21 0
|
22天前
|
存储 Python
GDAL一行代码将投影坐标系转为地理坐标系
【2月更文挑战第24天】本文介绍基于gdal模块,在命令行中通过GDAL命令的方式,将栅格遥感影像的投影坐标系转为地理坐标系的方法~
GDAL一行代码将投影坐标系转为地理坐标系
|
22天前
ArcGIS中ArcMap为不含坐标系的图层添加地理坐标系或投影坐标系
ArcGIS中ArcMap为不含坐标系的图层添加地理坐标系或投影坐标系
|
22天前
|
定位技术
ArcGIS矢量图层投影与地理坐标系转为投影坐标系——ArcMap
ArcGIS矢量图层投影与地理坐标系转为投影坐标系——ArcMap
|
8月前
cesium中绘制立方体、设置材质、操作相机及获取鼠标经纬度和高度的方法
cesium中绘制立方体、设置材质、操作相机及获取鼠标经纬度和高度的方法
125 0
|
定位技术
ArcGIS投影:地理坐标系转为投影坐标系
本文介绍在ArcMap软件中,对矢量图层或栅格图层进行投影(即将地理坐标系转为投影坐标系)的原理与操作方法~
965 1
ArcGIS投影:地理坐标系转为投影坐标系
|
数据处理 C#
基于C#的ArcEngine二次开发41:投影坐标系与地理坐标系接口、方法及示例代码(一)
基于C#的ArcEngine二次开发41:投影坐标系与地理坐标系接口、方法及示例代码
基于C#的ArcEngine二次开发41:投影坐标系与地理坐标系接口、方法及示例代码(一)
基于C#的ArcEngine二次开发41:投影坐标系与地理坐标系接口、方法及示例代码(三)
基于C#的ArcEngine二次开发41:投影坐标系与地理坐标系接口、方法及示例代码
基于C#的ArcEngine二次开发41:投影坐标系与地理坐标系接口、方法及示例代码(三)
|
API
使用Threejs创建几何体,动态添加几何体,删除几何体,添加坐标轴
使用Threejs创建几何体,动态添加几何体,删除几何体,添加坐标轴
374 0
使用Threejs创建几何体,动态添加几何体,删除几何体,添加坐标轴

热门文章

最新文章