Click here to Skip to main content
12,450,977 members (54,095 online)
Rate this:
 
Please Sign up or sign in to vote.
public class MainActivity extends Activity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
    }
 
    RelativeLayout rl = (RelativeLayout) findViewById(R.id.imageView5);
    ImageView iv;
    RelativeLayout.LayoutParams params; //; syntax error!! over HERE, params Error too 
    
    iv = new ImageView(this);
    iv.setBackgroundColor(Color.YELLOW);
    params = new RelativeLayout.LayoutParams(30, 40);
    params.leftMargin = 50;
    params.topMargin = 60;
    rl.addView(iv, params);
 
}//} and HERE too

Did I do something wrong? got from
http://stackoverflow.com/questions/3294590/set-the-absolute-position-of-a-view-in-android[^]
Posted 18-Jun-14 17:18pm
Eerven335

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

try like below
public class MainActivity extends Activity {
 
    RelativeLayout rl;
    ImageView iv;
    RelativeLayout.LayoutParams params;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        r1=(RelativeLayout) findViewById(R.id.imageView5);
        iv = new ImageView(this);
        iv.setBackgroundColor(Color.YELLOW);
        params = new RelativeLayout.LayoutParams(30, 40);
        params.leftMargin = 50;
        params.topMargin = 60;
        rl.addView(iv, params);
        
    }
 
 
}
  Permalink  
Comments
Eerven 18-Jun-14 23:53pm
   
thx DamithSL

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160826.1 | Last Updated 18 Jun 2014
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100