I'm just not able to set LinearLayout parameters programatically. Everything I try, I get this exact exception.
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) outerLayout.getLayoutParams();
params.bottomMargin = 50;
outerLayout.setLayoutParams(params);
java.lang.ClassCastException: android.widget.AbsListView$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
I have no idea why, but it seems I just can't get LinearLayout.LayoutParams on a view. outerLayout
is my LinearLayout I am instantiating it with findViewById(). I've tried importing different things but no luck.
Here is my xml that represents one item in a list view. outer_item_layout
is the layout i am calling getLayoutParams() on.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/outer_item_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="horizontal">
<TextView
android:id="@+id/modeName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="3"
android:text="Medium Text"
android:textSize="18dp" />
<ImageView
android:id="@+id/dropdown_speed"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_gravity="center"
android:layout_marginRight="20dp"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
android:src="@drawable/ic_dropdown"
tools:ignore="InvalidId" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/expandable_seekbar"
android:layout_width="match_parent"
android:layout_marginBottom="-50dip"
android:visibility="gone"
android:layout_height="50dip"
android:orientation="horizontal">
<SeekBar
android:id="@+id/custom_mode_speed_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp" />
</LinearLayout>