0
我想設置我的LinearLayout代碼端的寬度。我試圖找到一種方法,我可以將我的IcsSpinner的selectedNavigationItem大小設置爲選定的項目大小...當我將xLineLayout設置爲特定寬度時,實現此操作...但我需要動態調整大小。以編程方式設置在XML中聲明的LinearLayout的寬度
<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>
是否有任何方法來設置LinearLayout的寬度,而不是孩子?
UPDATE ...回答:
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)ll.getLayoutParams();
lp.width = 85; // set this to size...this is arbitrary number for proof of concept
ll.requestLayout();
這幾乎是正確的我的情況....我需要保存其他佈局參數在我的XML。因此,我需要這樣做:LinearLayout.LayoutParams lp =(LinearLayout.LayoutParams)ll.getLayoutParams(); \t \t lp.width = 85; \t \t ll.requestLayout(); – taraloca
當然,你也可以做到這一點,我只是保持簡單:) –