[英]How To Get Dynamically Created Imageview or textview clicked id or position in android?
[英]Position textview on top of clicked imageview
有沒有一種方法可以以編程方式添加TextView
並將其顯示在所單擊的ImageView
用戶旁邊?
我嘗試了類似的方法,但是沒有結果, TextView
被添加到布局的底部:
TextView score = new TextView(getBaseContext());
score.setText("Image clicked");
Rect rectf = new Rect();
im.getLocalVisibleRect(rectf);
AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 300, 270);
score.setLayoutParams(params);
layout.addView(score);
第一件事,永遠不要使用AbsoluteLayout ,永遠不要! 通常不建議使用AbsoluteLayout,因此不應使用它。 我建議您使用RelativeLayout
,然后只需要添加規則。
嘗試使用以下代碼段:
relativeLayout = new RelativeLayout(this);
par = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
par.addRule(RelativeLayout.RIGHT_OF, imageView.getId());
relativeLayout.addView(score, par);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.