我想将按钮从顶角移动到右下角(从一种布局到另一种布局),当我只使用一种布局即相对布局时,过渡效果非常好。 逻辑是:当我点击顶部线性布局时,按钮应移动到第二(底部)线性布局。但我面临这个错误:
java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
我的java代码是:
private void MoveBTN() {
//transition
TransitionManager.beginDelayedTransition(myLayout);
// View myBtn=findViewById(R.id.btn1);
//moveing button
RelativeLayout.LayoutParams LP=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
LP.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,RelativeLayout.TRUE);
LP.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,RelativeLayout.TRUE);
myButton1.setLayoutParams(LP);
//resizing button
ViewGroup.LayoutParams size=myButton1.getLayoutParams();
size.height=71;
size.width=65;
myButton1.setLayoutParams(size);
}
我的布局在图片my Layout
中给出答案 0 :(得分:1)
您的按钮位于LinearLayout内。所以施放RealativeLAyout.Params会抛出异常。尝试更改布局参数不是按钮,而是布局