android – 以编程方式设置scrollview的layoutparams时获取异常

android – 以编程方式设置scrollview的layoutparams时获取异常,第1张

概述我以编程方式设置scroolview的layoutparams时遇到异常.我已经尝试过但在执行此 *** 作时遇到异常.这是代码: sv = (ScrollView)findViewById(R.id.scrollView); sv.setBackgroundColor(Color.TRANSPARENT); ScrollView.LayoutParams lay 我以编程方式设置scroolvIEw的layoutparams时遇到异常.我已经尝试过但在执行此 *** 作时遇到异常.这是代码:

sv = (ScrollVIEw)findVIEwByID(R.ID.scrollVIEw);        sv.setBackgroundcolor(color.transparent);            ScrollVIEw.LayoutParams layoutParams = new ScrollVIEw.LayoutParams(                    ScrollVIEw.LayoutParams.MATCH_PARENT,ScrollVIEw.LayoutParams.MATCH_PARENT);            layoutParams.bottommargin = 100;            layoutParams.setmargins(0,100);            sv.setLayoutParams(layoutParams);

这是错误日志:

09-23 12:13:20.666: E/AndroIDRuntime(3284): Uncaught handler: thread main exiting due to uncaught exception09-23 12:13:20.696: E/AndroIDRuntime(3284): java.lang.classCastException: androID.Widget.FrameLayout$LayoutParams09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.relativeLayout$DependencyGraph.findRoots(relativeLayout.java:1291)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.relativeLayout$DependencyGraph.getSortedVIEws(relativeLayout.java:1238)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.relativeLayout.sortChildren(relativeLayout.java:279)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.relativeLayout.onMeasure(relativeLayout.java:299)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEw.measure(VIEw.java:7964)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.relativeLayout.measureChildHorizontal(relativeLayout.java:569)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.relativeLayout.onMeasure(relativeLayout.java:361)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEw.measure(VIEw.java:7964)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:3023)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:245)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEw.measure(VIEw.java:7964)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.linearLayout.measureVertical(linearLayout.java:464)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.linearLayout.onMeasure(linearLayout.java:278)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEw.measure(VIEw.java:7964)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:3023)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:245)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEw.measure(VIEw.java:7964)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:3023)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:245)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEw.measure(VIEw.java:7964)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEwRoot.performTraversals(VIEwRoot.java:763)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.vIEw.VIEwRoot.handleMessage(VIEwRoot.java:1633)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.os.Handler.dispatchMessage(Handler.java:99)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.os.Looper.loop(Looper.java:123)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at androID.app.ActivityThread.main(ActivityThread.java:4363)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at java.lang.reflect.Method.invokeNative(Native Method)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at java.lang.reflect.Method.invoke(Method.java:521)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:618)09-23 12:13:20.696: E/AndroIDRuntime(3284):     at dalvik.system.NativeStart.main(Native Method)

这是xml文件:

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:ads="http://schemas.androID.com/apk/lib/com.Google.ads"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:layout_centerHorizontal="true"    androID:orIEntation="vertical" >    <relativeLayout        androID:ID="@+ID/frameLayout"        androID:layout_wIDth="fill_parent"        androID:layout_height="fill_parent" >        <ScrollVIEw            androID:ID="@+ID/scrollVIEw"            androID:layout_wIDth="fill_parent"            androID:layout_height="wrap_content"            androID:layout_marginBottom="90.0dip"            androID:layout_marginleft="1.0dip"            androID:layout_marginRight="1.0dip"            androID:layout_margintop="-2.0dip"            androID:animateLayoutChanges="true"            androID:fadeScrollbars="true"            androID:fadingEdge="none" >            <!-- androID:layout_marginBottom="60.0dip" -->            <!-- androID:fillVIEwport="true" -->            <relativeLayout                androID:layout_wIDth="fill_parent"                androID:layout_height="wrap_content"                androID:orIEntation="vertical"                androID:visibility="visible" >                <ImageVIEw                    androID:ID="@+ID/QuestionImageVIEw"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:visibility="visible" />                <TextVIEw                    androID:ID="@+ID/tv"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:layout_below="@ID/QuestionImageVIEw"                    androID:fadingEdge="vertical"                    androID:scrollbars="vertical" />                <TextVIEw                    androID:ID="@+ID/questionnumber"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:layout_alignParentRight="true"                    androID:fadingEdge="vertical"                    androID:scrollbars="vertical" />                <TextVIEw                    androID:ID="@+ID/question"                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:layout_alignParentRight="true"                    androID:layout_below="@ID/tv"                    androID:fadingEdge="vertical"                    androID:padding="10dp"                    androID:scrollbars="vertical"                    androID:text=""                    androID:textcolor="@color/dark_green" />                <RadioGroup                    androID:ID="@+ID/radioGroup1"                    androID:layout_wIDth="fill_parent"                    androID:layout_height="wrap_content"                    androID:layout_below="@ID/question"                    androID:orIEntation="vertical" >                    <Radiobutton                        androID:ID="@+ID/option1"                        androID:layout_wIDth="wrap_content"                        androID:layout_height="wrap_content"                        androID:text="" />                    <ImageVIEw                        androID:layout_wIDth="fill_parent"                        androID:layout_height="1.0dp"                        androID:background="@drawable/thinnest_blue_gradIEnt" />                    <Radiobutton                        androID:ID="@+ID/option2"                        androID:layout_wIDth="wrap_content"                        androID:layout_height="wrap_content"                        androID:text="" />                    <ImageVIEw                        androID:layout_wIDth="fill_parent"                        androID:layout_height="1.0dp"                        androID:background="@drawable/thinnest_blue_gradIEnt" />                    <Radiobutton                        androID:ID="@+ID/option3"                        androID:layout_wIDth="wrap_content"                        androID:layout_height="wrap_content"                        androID:text="" />                    <ImageVIEw                        androID:layout_wIDth="fill_parent"                        androID:layout_height="1.0dp"                        androID:background="@drawable/thinnest_blue_gradIEnt" />                    <Radiobutton                        androID:ID="@+ID/option4"                        androID:layout_wIDth="wrap_content"                        androID:layout_height="wrap_content"                        androID:text="" />                </RadioGroup>            </relativeLayout>        </ScrollVIEw>    </relativeLayout>    <relativeLayout        androID:ID="@+ID/relativequestion"        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:layout_alignParentBottom="true" >        <com.Google.ads.AdVIEw            androID:ID="@+ID/ad"            androID:layout_wIDth="fill_parent"            androID:layout_height="wrap_content"            androID:layout_alignParentBottom="true"            ads:adSize="SMART_BANNER"            ads:adUnitID="a1501e5633125fb"            ads:loadAdOnCreate="true"            ads:testDevices="TEST_EMulATOR,123456789ABCDEF" />        <linearLayout            androID:ID="@+ID/newquestion"            androID:layout_wIDth="fill_parent"            androID:layout_height="40.0dip"            androID:layout_above="@ID/ad"            androID:background="#ff777777"            androID:orIEntation="horizontal" >            <button                androID:ID="@+ID/Prevbutton"                androID:layout_wIDth="fill_parent"                androID:layout_height="fill_parent"                androID:layout_centerInParent="true"                androID:layout_marginleft="5.0dip"                androID:layout_weight="1.0"                androID:background="@drawable/ibtn"                androID:onClick="onPrevbuttonClick"                androID:text="Prev" />            <button                androID:ID="@+ID/Nextbutton"                androID:layout_wIDth="fill_parent"                androID:layout_height="fill_parent"                androID:layout_centerInParent="true"                androID:layout_marginleft="5.0dip"                androID:layout_weight="1.0"                androID:background="@drawable/ibtn"                androID:onClick="onNextbuttonClick"                androID:text="Next" />            <button                androID:ID="@+ID/Skipbutton"                androID:layout_wIDth="fill_parent"                androID:layout_height="fill_parent"                androID:layout_centerInParent="true"                androID:layout_marginleft="5.0dip"                androID:layout_weight="1.0"                androID:background="@drawable/ibtn"                androID:onClick="onSkipbuttonClick"                androID:text="Skip" >            </button>            <button                androID:ID="@+ID/submitbutton"                androID:layout_wIDth="fill_parent"                androID:layout_height="fill_parent"                androID:layout_centerInParent="true"                androID:layout_marginleft="5.0dip"                androID:layout_marginRight="5.0dp"                androID:layout_weight="1.0"                androID:background="@drawable/ibtn"                androID:onClick="onsubmitbuttonClick"                androID:text="submit" />        </linearLayout>    </relativeLayout></relativeLayout>

请帮帮我.谢谢.

解决方法 ScrollVIEw的父级是relativeLayout,为此你应该使用relativeLayout.LayoutParams:

relativeLayout.LayoutParams lp = (relativeLayout.LayoutParams) sv            .getLayoutParams();    lp.setmargins(0,100);
总结

以上是内存溢出为你收集整理的android – 以编程方式设置scrollview的layoutparams时获取异常全部内容,希望文章能够帮你解决android – 以编程方式设置scrollview的layoutparams时获取异常所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1123111.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存