I'm trying to do something like this in android:
// If the parent is a viewpager
if (parentIsViewPager)
{
// Retrieve the view's layout informations specific to viewpagers
ViewPager.MarginLayoutParams marginLayoutParams = (ViewPager.MarginLayoutParams) getLayoutParams();
}
// If the parent is not a viewpager (mainly a viewgroup)
else
{
// Retrieve the view's layout informations for a viewgroup
ViewGroup.MarginLayoutParams marginLayoutParams = getLayoutParams();
}
Log.i("Test","marginLayoutParams.leftMargin = " + marginLayoutParams.leftMargin);
Unfortunately, the IDE (Android Studio 1.5.1) tells me it cannot find declaration for layoutParams in the last line above... But I declared it in the if statements!
I guess there is something about scope in here but as the following code in my project is really big, I cannot duplicate it in each if statement.
So how can I achieve this or something similar?
EDIT:
As I guessed, and this was confirmed in the comments, this is a matter of scope. Ok, got it.
Thanks for your help guys.