there are 2 imageview in layout with different position so when I clicked black one I want to make a new card same position of imageview and of course for red one.For example ,black one's layout_alignParentTop="true" and I want to use this information to making a new card. How can I get position of imageviews and use them when I making a new card?
            Asked
            
        
        
            Active
            
        
            Viewed 43 times
        
    1
            
            
        - 
                    Possible duplicate of [How to get the width and height of an android.widget.ImageView?](http://stackoverflow.com/questions/4680499/how-to-get-the-width-and-height-of-an-android-widget-imageview) – aug Feb 04 '16 at 18:03
1 Answers
0
            If you have margines, you can make this:
My layout:
<RelativeLayout 
android:id="@+id/activity_main_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!" />
<ImageView
    android:id="@+id/activity_main_red_card"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_red_dark"
    android:layout_marginBottom="@dimen/activity_main_layout_margin_bottom"
    android:layout_marginLeft="@dimen/activity_main_layout_margin_left"
    android:layout_marginRight="@dimen/activity_main_layout_margin_right"
    android:layout_marginTop="@dimen/activity_main_layout_marginB_top"/></RelativeLayout>
My activity:
public class MainActivity extends AppCompatActivity {
RelativeLayout mRelativeLayout;
ImageView mRedCard, mNewCard;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mRelativeLayout = (RelativeLayout) findViewById(R.id.activity_main_relative_layout);
    mRedCard = (ImageView) findViewById(R.id.activity_main_red_card);
    mNewCard = new ImageView(this);
    mNewCard.setBackgroundColor(getColor(R.color.colorPrimary));
    takePosition();
}
public void takePosition() {
    RelativeLayout.LayoutParams mLayoutParams = (RelativeLayout.LayoutParams) mRedCard.getLayoutParams();
    mNewCard.setLayoutParams(mLayoutParams);
    mRelativeLayout.addView(mNewCard);
}}
Also you can check my example
 
    
    
        Cabezas
        
- 9,329
- 7
- 67
- 69
- 
                    You have to put RelativeLayout and then you can put your cards inside. If you have LinearLayout, you have to changes RelativeLayout.LayoutParams to LinearLayout.LayoutParams – Cabezas Feb 04 '16 at 21:02
