android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutPara

2019-11-09 10:35:14

参考地址 android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutPara

<LinearLayout

            android:id="@+id/ll_card"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:orientation="vertical" >

 

            <ImageView

                android:id="@+id/iv_move"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:background="@drawable/blue_line" />

 

            

        </LinearLayout>

上面是布局文件,我要早代码中重新设置ImageView的宽度,用以下方法:


LayoutParams layoutParams = (LayoutParams) iv_move.getLayoutParams();

layoutParams.width = move_width;

iv_move.setLayoutParams(layoutParams);


运行的时候会报错: Caused by: java.lang.ClassCastException:android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.Re




解决方法:ImageView是LinearLayout的子控件,它的LayoutParams 应该是LinearLayout给他的。所以应该是LinearLayout.LayoutParam 。


代码改成:





LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) iv_move.getLayoutParams();

layoutParams.width = move_width;

iv_move.setLayoutParams(layoutParams);



  • 2018-03-04 10:15:33

    HTTP代理协议 HTTP/1.1的CONNECT方法

    我们平时使用HTTP协议无非就是GET、POST这些方法,但是HTTP的内容远不止那些。今天就来说说HTTP代理使用的CONNECT。这个不是在网页开发上用的,如果没兴趣就跳过吧。

  • 2018-03-05 11:30:04

    iOS wkwebkit 播放HTML5 视频 全屏问题解决

    使用html5 的video标签播放视频的时候,限制视频的尺寸,在android上是没有问题的,但是在ios上发现,视频没有开始播放的时候还是好的,但是一旦播放开是,就会全屏,非常奇怪。

  • 2018-03-07 14:35:32

    centos7下yum安装ffmpeg

    安装EPEL Release,因为安装需要使用其他的repo源,所以需要EPEL支持 yum install -y epel-release

  • 2018-03-08 09:44:12

    前端性能监控:window.performance

    Web Performance API允许网页访问某些函数来测量网页和Web应用程序的性能,包括 Navigation Timing API和高分辨率时间数据。