简体   繁体   English

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

[英]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.

相关问题 java.lang.ClassCastException:android.widget.RelativeLayout $ LayoutParams无法转换为android.widget.LinearLayout $ LayoutParams - java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams java.lang.ClassCastException:android.view.ViewGroup$LayoutParams 不能转换为 android.widget.RelativeLayout$LayoutParams - java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams java.lang.ClassCastException:android.widget.LinearLayout $ LayoutParams无法转换为android.widget.FrameLayout - java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.FrameLayout java.lang.ClassCastException:android.widget.RelativeLayout $ LayoutParams无法强制转换为android.support.v7.widget.RecyclerView $ LayoutParams - java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams java.lang.ClassCastException:android.widget.LinearLayout $ LayoutParams无法转换为android.widget.AbsListView $ LayoutParams - java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams Android java.lang.ClassCastException:无法将android.widget.RelativeLayout强制转换为android.widget.EditText - Android java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.EditText java.lang.ClassCastException:android.widget.RelativeLayout无法强制转换为android.widget.EditText - java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.EditText Android java.lang.ClassCastException:android.widget.LinearLayout $ LayoutParams无法强制转换为android.widget.AbsListView $ LayoutParams - Android java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams android.widget.FrameLayout $ LayoutParams无法转换为android.widget.AbsListView $ LayoutParams - android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 不能转换为 android.support.v7.widget.RecyclerView$LayoutParams - java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM