这是我的活动:
public class Main2Activity extends FragmentActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
RelativeLayout relativeLayout = findViewById(R.id.p1);
relativeLayout.setClipChildren(false);
relativeLayout.setClipToPadding(false);
Log.e("WIDTH"," "+relativeLayout.getLayoutParams().width);// prints 200
Log.e("HEIGHT"," "+relativeLayout.getLayoutParams().height);// prints 200
RelativeLayout relativeLayout2 = findViewById(R.id.p2);
relativeLayout2.setClipChildren(false);
relativeLayout2.setClipToPadding(false);
final ImageView str = findViewById(R.id.star);
final MyAnimation myAnimation = new MyAnimation();
myAnimation.setDuration(1000);
myAnimation.setView(str);
str.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
str.startAnimation(myAnimation);
}
});
}
}
这是我的自定义动画
class MyAnimation extends Animation {
private int dH;
private int dW;
private int iH;
private int iw;
private ImageView targetView;
public MyAnimation() {
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float nh = iH + dH * interpolatedTime;
float nW = iw + dW * interpolatedTime;
Log.e("WIDTH", "applyTransformation: "+nW ); // final value = 1100
Log.e("HEIGHT", "applyTransformation: "+nh );// final value =1100
targetView.getLayoutParams().width = (int) nW;
targetView.getLayoutParams().height = (int) nh;
targetView.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
public void setView(ImageView str) {
this.targetView = str;
ViewGroup.LayoutParams lp = str.getLayoutParams();
iH = lp.height;
iw =lp.width;
dH =1000;
dW = 1000;
}
}
我的Xml看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/p2"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="100dp"
android:clipChildren="false"
android:id="@+id/p1"
android:layout_height="100dp"
android:background="@color/cardview_dark_background"
android:layout_centerInParent="true"
android:layout_gravity="center">
<ImageView
android:id="@+id/star"
android:layout_width="50dp"
android:layout_centerInParent="true"
android:layout_height="50dp"
android:src="@android:drawable/btn_star" />
</RelativeLayout>
</RelativeLayout>
问题 我希望使自己的星星溢出 RelativeLayout 父对象并变大,但似乎没有这样做,所以我将 setClipChildren和setClipToPadding都设置为false ,但似乎没有任何效果,它无法通过可以帮助我