3

I'm trying to program a weekly calendar following the exampled posted on:
How can I create a weekly calendar view for an Android Honeycomb application?
I have added to the XML file posted there a time marker line that is suppose to be on the current hour. To do that I use:

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

This LinearLayout is inside a RelativeLayout and both of them inside a ScrollView.
I'm trying to "move" this line via programming, by modifying the layout_margintTop with these lines:

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

But I get an error in lp = lay.getLayoutParams() telling me that it can't convert from ViewGroup.LayoutParams to LinearLayout.LayoutParams.

What am I doing wrong?

Community
  • 1
  • 1
mgrdiez
  • 67
  • 1
  • 10

1 Answers1

5

But I get an error in lp = lay.getLayoutParams() telling me that it can't convert from ViewGroup.LayoutParams to LinearLayout.LayoutParams.

If the LinearLayout is wrapped by the RelativeLayout than its LayoutpParams are of type RelativeLayout.LayoutParams(the child takes the LayoutParams from the parent). You also, most likely, imported the wrong classes for the LayoutParams that you use in the code.

LinearLayout lay = (LinearLayout) findViewById(R.id.currentTimeMarkerLinearLayout);
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)lay.getLayoutParams();
user
  • 86,916
  • 18
  • 197
  • 190
  • Thank you very much Luksprog, I waste a lot of time because of this issue. Righ now is working very good! – mgrdiez Dec 06 '12 at 16:16