I have a two imageView in a Relative Layout. Is it possible to change the Position of one imageview dynamically. while the other remain constant.?

北城以北 提交于 2019-12-11 07:53:29

问题


I have Two Image Views Defined in Xml. I want to Change the Position of One of them Dynamically while the Other remains constant.?? Any Suggestions. Thanx.


回答1:


Yes off course, this is damn possible.Use LayouParam

        ImageView img1=(ImageView) findViewById(R.id.imageview);
    ImageView img2=(ImageView) findViewById(R.id.imageview);

    RelativeLayout.LayoutParams lp2=new RelativeLayout.LayoutParams(100, 100);
    lp2.addRule(RelativeLayout.ALIGN_RIGHT,img2.getId());
    img1.setLayoutParams(lp2);

Setting Margin

lp2.setMargins(Left, TOp, right,Bottom);



回答2:


You can do it by providing new rules for RelativeLayout.LayoutParams. Just do something like this:

RelativeLayout.LayoutParams params = imageView2.getLayoutParams();
params.addRule(RelativeLayout.CENTER_IN_PARENT);
imageView2.setLayoutParams(params);



回答3:


Lets assume your imageView1 which would remain Constant is center aligned in parent. And Your Second ImageView imageView2 is aligned left to imageView1, and now you want to align it to below of imageView1. Use following to achieve the same,

RelativeLayout.LayoutParams params = imageView2.getLayoutParams(); param.addRule(RelativeLayout.BELOW, R.id.imageView1); imageView2.setLayoutParams(params);




回答4:


Use the layout property like this:

imageView.layout(l,t,r,b);

Where the l stands for left, t for top, etc.



来源:https://stackoverflow.com/questions/8876131/i-have-a-two-imageview-in-a-relative-layout-is-it-possible-to-change-the-positi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!