I have Framelayout with 2 components
- Linear layout
- ImageView
I want to set android:layout_marginTop="100dp"
to the Imageview
(programatically )
Stackoverflow solutions says :
ImageView imgv = (ImageView)findViewById(R.id.redLine);
FrameLayout frameLayout= (FrameLayout)findViewById(R.id.frameLayout);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) frameLayout.getLayoutParams();
layoutParams.setMargins(100, 0, 0, 0);
imgv.setLayoutParams(layoutParams);
But I get Cast exception :
ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
Question
How can I set this :android:layout_marginTop="100dp"
to the Imageview
(programatically ) ?
Additional info :
Imports :
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;