簡體   English   中英

如何在Android中的另一個imageview(不是容器)的固定點xy處添加imageview

[英]How to add an imageview at a fix point x-y of another imageview (not the container) in Android

我有一個相對的布局,其中放置了一個imageview。 在此imageview的onTouch事件中,我編寫了代碼,以在容器的xy點處動態地在該圖像上添加另一個imageview(標記圖像)。

我想縮放主imageview,也想將動態添加的imageview駐留在圖像的固定位置(而不是容器)。

也就是說,當我縮放主圖像時,標記圖像也應移動到主圖像縮放的位置,並將固定在圖像的x,y點。

由於您的容器是相對布局,因此您可以使內部imageView與外部imageView對齊,並在頂部邊緣和左側邊緣放置顏色。 x和y是要放置圖像的點的坐標,some_x和some_y是innerView的大小

ImageView outerView = (ImageView) findViewById(R.id.outer_image_view);
ImageView innerView = (ImageView) findViewById(R.id.inner_image_view);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(some_x, some_y)
rlp.addRule(RelativeLayout.ALIGN_LEFT, R.id.outer_image_view);
rlp.addRule(RelativeLayout.ALIGN_TOP, R.id.outer_image_view);
rlp.leftMargin = x;
rlp.topMargin = y;
innerView.setLayoutParams(rlp);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM