Android的:检索layout_marginBottom编程? [英] Android: Retrieve layout_marginBottom programmatically?
问题描述
在我一个的LinearLayout我已设置的android:layout_marginBottom
在我的XML。我只是想找回价值。
In my a LinearLayout I have set android:layout_marginBottom
in my XML. I just want to retrieve that value.
只是的LayoutParams
不给我访问 bottomMargin
。我试图强制转换:
Just LayoutParams
doesn't give me access to bottomMargin
. I tried to typecast :
row1 = (LinearLayout) findViewById(R.id.mainrow1);
LinearLayout.LayoutParams row1Params = (android.widget.LinearLayout.LayoutParams) row1.getLayoutParams();
但是这给了我运行时异常ClassCastException异常。
but this gives me Runtime exception ClassCastException.
主要目标是我在嵌套LinearLayouts&放按钮;我想设置的LinearLayout的高度/宽度编程按钮,即会自动inturn设定高度。我也第一次布局后添加bottomMargin - 所以有2行之间的空间。
The main aim is I got buttons in nested LinearLayouts & I want to set height/width of LinearLayout programmatically that will inturn auto set height of buttons. I have added bottomMargin after 1st layout - so there is space between 2 rows.
推荐答案
根据下面的逻辑改变你的按钮布局,
Change Your layout of Button according to following logic,
设置为Layout_Width 0dip
设置Layout_Weight 1
设置Layout_Height为WRAP_CONTENT
set Layout_Width to 0dip set Layout_Weight to 1 set Layout_Height to Wrap_Content
这篇关于Android的:检索layout_marginBottom编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!