imageview位置的一些问题 [英] Some Question of imageview position

查看:106
本文介绍了imageview位置的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在单击按钮时选择的位置上设置imageview。(位置不仅仅是图像)

例如

http://upic.me/i/tv/sample1.jpg

http://upic.me/i/qm/0sample2.jpg

http://upic.me/i/jo/sample3.jpg



我试试这个 http://stackoverflow.com/questions/ 3294590 /设置绝对位置的机器人视图
模拟它时的
错误。



How to set imageview on the position I choose when click button.(position not just image)
e.g.
http://upic.me/i/tv/sample1.jpg
http://upic.me/i/qm/0sample2.jpg
http://upic.me/i/jo/sample3.jpg

I try this http://stackoverflow.com/questions/3294590/set-the-absolute-position-of-a-view-in-android
when simulated it error.

public class MainActivity extends Activity {
	
    RelativeLayout rl= (RelativeLayout) findViewById(R.id.imageView5);;
    ImageView iv;
    RelativeLayout.LayoutParams params;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        onClickBtn();
        
        int yellow_iv_id = 123; // Some arbitrary ID value.

        iv = new ImageView(this);
        iv.setId(yellow_iv_id);
        iv.setBackgroundColor(Color.YELLOW);
        params = new RelativeLayout.LayoutParams(30, 40);
        params.leftMargin = 50;
        params.topMargin = 60;
        rl.addView(iv, params);

        iv = new ImageView(this);
        iv.setBackgroundColor(Color.RED);
        params = new RelativeLayout.LayoutParams(30, 40);
        params.leftMargin = 80;
        params.topMargin = 90;

        // This line defines how params.leftMargin and params.topMargin are interpreted.
        // In this case, "<80,90>" means <80,90> to the right of the yellow ImageView.
        params.addRule(RelativeLayout.RIGHT_OF, yellow_iv_id);

        rl.addView(iv, params);
        
    }
/*
	public void onClickBtn(){
    		Button btn1=(Button)findViewById(R.id.button1);
    
  	  	btn1.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				TextView textView=(TextView)findViewById(R.id.textView1);
				textView.setText("Go to postion A");
			}
    	});
    }*/
}

推荐答案

这篇关于imageview位置的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆