[英]java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
I am using this code to move and resize the button in a relative layout... 我正在使用此代码在相对布局中移动和调整按钮的大小...
Program crashes when I touch on the screen, what can be the reason.? 当我触摸屏幕时程序崩溃,这可能是原因。
ViewGroup relativeL;
onCreate(){
relativeL = (ViewGroup) findViewById(R.id.relativeLayout);
relativeL.setOnTouchListener(new RelativeLayout.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
methodMove();
return true;
}
});
}
public void methodMove(){
View button = findViewById(R.id.helloButton);
TransitionManager.beginDelayedTransition(relativeL);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
relativeL.setLayoutParams(layoutParams);
button.setLayoutParams(new RelativeLayout.LayoutParams(130,250));
}
I have tried making relative layout as just RelativeLayout type instead of ViewGroup, still didnot work. 我尝试将相对布局设置为RelativeLayout类型而不是ViewGroup,仍然无法正常工作。 Guidance,...thank you in advance..
指导,...谢谢你..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="my context"
android:id="@+id/relativeLayout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/helloButton"/>
I'm mobile and I can't check the code but could you try changing 我是移动用户,无法检查代码,但可以尝试更改
button.setLayoutParams(new RelativeLayout.LayoutParams(130,250));
To 至
button.setLayoutParams(new FrameLayout.LayoutParams(130,250));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.