gpt4 book ai didi

java.lang.ClassCastException : android. widget.RelativeLayout$LayoutParams 无法转换为 android.widget.FrameLayout$LayoutParams

转载 作者:太空宇宙 更新时间:2023-11-04 12:56:09 26 4
gpt4 key购买 nike

我正在使用此代码在相对布局中移动按钮并调整其大小...

触摸屏幕时程序崩溃,可能是什么原因?

    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));
}

我尝试将相对布局设置为RelativeLayout类型而不是ViewGroup,但仍然不起作用。指导,...提前谢谢您..

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

最佳答案

我是移动设备,无法检查代码,但您可以尝试更改

button.setLayoutParams(new RelativeLayout.LayoutParams(130,250));

button.setLayoutParams(new FrameLayout.LayoutParams(130,250));

关于java.lang.ClassCastException : android. widget.RelativeLayout$LayoutParams 无法转换为 android.widget.FrameLayout$LayoutParams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35372814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com