java-类型不匹配:无法从ViewGroup.LayoutParams转换为LinearLayout.LayoutParams

java-类型不匹配:无法从ViewGroup.LayoutParams转换为LinearLayout.LayoutParams,第1张

概述我正在尝试按照以下示例发布每周日历:HowcanIcreateaweeklycalendarviewforanAndroidHoneycombapplication?我已经在该XML文件中添加了一个时间标记行,该行应该位于当前时间.为此,我使用了:<LinearLayoutandroid:id="@+id/currentTimeMarkerLinearLayout"an

我正在尝试按照以下示例发布每周日历:
How can I create a weekly calendar view for an Android Honeycomb application?
我已经在该XML文件中添加了一个时间标记行,该行应该位于当前时间.为此,我使用了:

<linearLayout    androID:ID="@+ID/currentTimeMarkerlinearLayout"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:layout_marginleft="0dp"    androID:layout_margintop="120dp"    androID:baselineAligned="false"    androID:orIEntation="horizontal"    androID:padding="0dp" >  <VIEw      androID:layout_wIDth="0dp"      androID:layout_height="3dp"      androID:layout_weight="1" />  <VIEw      androID:ID="@+ID/currentTimelineVIEw"      androID:layout_wIDth="0dp"      androID:layout_height="1dp"      androID:layout_weight="14"      androID:background="@color/dark_blue" /></linearLayout>

此linearLayout在relativeLayout内部,并且两者都在ScrollVIEw中.
我试图通过编程,通过使用以下几行修改layout_marginttop来“移动”这一行:

int dipValue = 720; // we want to convert this dip value to pixResources r = getResources();float pix = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,    dipValue, r.getdisplayMetrics());linearLayout lay =(linearLayout) findVIEwByID(R.ID.currentTimeMarkerlinearLayout);linearLayout.LayoutParams lp = lay.getLayoutParams();lp.setmargins(0, (int) pix, 0, 0);lay.setLayoutParams(lp);  

但是我在lp = lay.getLayoutParams()中遇到一个错误,告诉我它无法从VIEwGroup.LayoutParams转换为linearLayout.LayoutParams.

我究竟做错了什么?

解决方法:

But I get an error in lp = lay.getLayoutParams() telling me that it
can’t convert from VIEwGroup.LayoutParams to
linearLayout.LayoutParams.

如果linearLayout由relativeLayout包装,则其LayoutpParams的类型为relativeLayout.LayoutParams(子级从父级获取LayoutParams).您还很可能为在代码中使用的LayoutParams导入了错误的类.

linearLayout lay = (linearLayout) findVIEwByID(R.ID.currentTimeMarkerlinearLayout);relativeLayout.LayoutParams lp = (relativeLayout.LayoutParams)lay.getLayoutParams();

总结

以上是内存溢出为你收集整理的java-类型不匹配:无法从ViewGroup.LayoutParams转换为LinearLayout.LayoutParams全部内容,希望文章能够帮你解决java-类型不匹配:无法从ViewGroup.LayoutParams转换为LinearLayout.LayoutParams所遇到的程序开发问题。

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

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

原文地址:https://54852.com/web/1086158.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存