I am trying to set the width of my LinearLayout code side. I am trying to find a way that I can size my selectedNavigationItem of my IcsSpinner to the selected item size…when I set the linearLayout in xml to a certain width, this is achieved…but I need dynamic sizing.
<LinearLayout
android:id="@+id/spinner_ll"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<com.actionbarsherlock.internal.widget.IcsSpinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
Is there any way to set the width of the LinearLayout, not the child?
UPDATE…ANSWER:
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)ll.getLayoutParams();
lp.width = 85; // set this to size...this is arbitrary number for proof of concept
ll.requestLayout();
You can set the layout parameters from code like this:
You can convert dps to pixels in code like this:
Take a look at the documentation here: https://developer.android.com/reference/android/util/TypedValue.html#applyDimension(int, float, android.util.DisplayMetrics)