2012-12-06 52 views
3

我想下面的编程每周日历所示例张贴在:
How can I create a weekly calendar view for an Android Honeycomb application?
我已经加入到XML文件张贴有时间标记行假设是在当前小时。要做到这一点我用:类型不匹配:不能从ViewGroup.LayoutParams转换为LinearLayout.LayoutParams

<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> 

LinearLayoutRelativeLayout且二者的ScrollView内内。
我试图通过编程“动”这一行,通过修改layout_margintTop这些行:

int dipValue = 720; // we want to convert this dip value to pix 
Resources 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

我在做什么错?

回答

4

但我得到了LP = lay.getLayoutParams()的错误告诉我,它 不能转换从ViewGroup.LayoutParams到 LinearLayout.LayoutParams。

如果LinearLayoutRelativeLayout比其LayoutpParams包裹是RelativeLayout.LayoutParams类型(子取从父LayoutParams)的。你也很可能导入了你在代码中使用的LayoutParams的错误类。

LinearLayout lay = (LinearLayout) findViewById(R.id.currentTimeMarkerLinearLayout); 
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)lay.getLayoutParams(); 
+0

非常感谢你Luksprog,我浪费了很多时间因为这个问题。现在Righ工作非常好! – mgrdiez

相关问题