2012-12-06 48 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

相關問題