,所以我創造我的看法編程像這樣:獲取Android的一個編程方式創建的ImageView的座標
for (int i = 0; i < num_devices; i++) {
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams vp = new LinearLayout.
LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(vp);
try {
Class res = R.drawable.class;
Field field = res.getField(device_types.get(i));
int resId = field.getInt(null);
imageView.setImageResource(resId);
}
catch (Exception e) {
Log.e("MyTag", "Failure to get drawable id.", e);
}
LinearLayout link_devices = (LinearLayout) findViewById(R.id.link_devices);
link_devices.addView(imageView);
}
,我試圖讓ImageView的座標:
我曾嘗試以下方法,但我沒有得到任何地方
imageView.getDrawable().getBounds().centerX() /centreY
imageView.getX()/getY
imageView.getLocationInWindow();/onScreen();
可能有人請向我解釋如何得到這是繪製圖像的cooridinates這樣我就可以畫一個框周圍或繪製兩個圖像之間的線(即計劃的功能)
你最終做了什麼?目前有同樣的問題。 – DanCat
@DanCat檢索getTop()和getLeft()適用於您的x,y座標。 – portfoliobuilder