Android得到控件在屏幕中的坐标
来源:互联网 发布:网络安全教育讲话稿 编辑:程序博客网 时间:2024/05/01 07:29
getLocationOnScreen
getLocationInWindow
getLeft
如果在Activity的OnCreate()事件输出那些参数,是全为0,要等UI控件都加载完了才能获取到这些。
- package xiaosi.location;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.ImageView;
- public class LocationActivity extends Activity {
- /** Called when the activity is first created. */
- private ImageView t = null;
- private Button button = null;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- t = (ImageView)findViewById(R.id.l);
- button = (Button)findViewById(R.id.button);
- button.setOnClickListener(new buttonListener());
- }
- public class buttonListener implements OnClickListener{
- public void onClick(View v)
- {
- int[] location = new int[2];
- t.getLocationOnScreen(location);
- int x = location[0];
- int 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());
- }
- }
- }
- <?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"/>
- <ImageView
- android:id="@+id/l"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:src="@drawable/a" />
- </LinearLayout>
0 0
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android 得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- Android得到控件在屏幕中的坐标
- (4.1.40.1)Android得到控件在屏幕中的坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- Android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- android获得控件在屏幕中的绝对坐标
- 使用libxml解析HTML -- DTHTMLParser
- pandas的read_csv()函数读取的文件路径问题
- 数组-02. 打印杨辉三角
- 01 storm 源码阅读 storm的进程间消息通信实现netty server实现
- Binary Tree Right Side View
- Android得到控件在屏幕中的坐标
- cf554题意的理解和组合问题
- Java List 用法代码分析 非常详细
- 循环-18. 龟兔赛跑
- 02 storm 源码阅读 storm的进程间消息通信实现netty client实现
- 进程同步及避免死锁经典问题
- 关于byte 进制 float String 编码 16进制字符串转16进制byte的问题
- MySQL 基本操作语句
- 图解Javascript上下文与作用域