如何设置安卓layout_alignParentLeft属性来的ImageView在code? [英] How to set android:layout_alignParentLeft attribute to imageview in code?
本文介绍了如何设置安卓layout_alignParentLeft属性来的ImageView在code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现在code同样的事情,因为它是在这个XML(这ImageView的是相对布局内):
< ImageView的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:SRC =@可绘制/标志/>
我知道如何设置布局的宽度和高度,但不知道如何设置layout_alignParentLeft =真。
难道possbile为此在code?
解决方案
RelativeLayout.LayoutParams PARAMS =
新RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT,RelativeLayout.TRUE);
imageView.setLayoutParams(PARAMS);
I want to achieve the same thing in code as it is in this xml (this imageview is inside relative layout):
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="@drawable/logo"/>
I know how to set layout width and height, but don't know how to set layout_alignParentLeft="true".
Is it possbile to do this in code?
解决方案
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
imageView.setLayoutParams(params);
这篇关于如何设置安卓layout_alignParentLeft属性来的ImageView在code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文