Click here to Skip to main content
15,883,997 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Java
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

1 solution

try like below
Java
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);
        
    }

 
}
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900