0

我有:

    <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"

如何在代码中实现这一点?

4

2 回答 2

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):
于 2012-12-15T15:44:03.177 回答
-4

试试这个

   ImageView image= (ImageView)findViewById(R.id.logo);
  image.setLayoutParams(new RelativeLayout.LayoutParams(width, height, Gravity.BOTTOM | Gravity.LEFT));
于 2012-12-15T15:54:26.137 回答