我是android新手,我想檢索XML文件中的按鈕信息。 (特別是margin_top和margin_left)。在那之後,我想動態地給這個特定的按鈕添加另一個邊距。我可以創建新的按鈕與新的保證金,但我不能檢索當前的按鈕邊距..如何檢索xml中的按鈕信息
任何幫助,將不勝感激。
android.view.ViewGroup.LayoutParams lay = btn1.getLayoutParams();
這個外行對象持有的所有信息,但我不能從那個利潤。
我使用下面的代碼創建了我的按鈕。
RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeTest);
Button btn3 = new Button(TestActivity.this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.setMargins(200, 200, 200, 200);
layout.addView(btn3, params);
查看我的更新回答 –