我有:
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="@string/logo"
android:onClick="LogoAnimate"
android:src="@drawable/logo" />
我需要改变:
android: layout_centerHorizontal = "true"
android: layout_centerVertical = "true"
为:
android: layout_alignParentBottom = "true"
android: layout_alignParentLeft = "true"
如何在代码中实现此功能?
答案 0 :(得分:1)
使用LayoutParams
执行此操作:
RelativeLayout.LayoutParams params =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.FALSE);
params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.FALSE);
ImageView img1 = (ImageView) findViewById(R.id.logo);
img1.setLayoutParams(params):
答案 1 :(得分:-4)
试试这个
ImageView image= (ImageView)findViewById(R.id.logo);
image.setLayoutParams(new RelativeLayout.LayoutParams(width, height, Gravity.BOTTOM | Gravity.LEFT));