我想要獲得我的RelativeLayout
的尺寸。在R.id中沒有RelativeLayout ID獲取RelativeLayout的尺寸
我許多告知使用如下代碼:
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.myRelativeLayout);
int layoutWidth = relativeLayout.getWidth();
int layoutHeight = relativeLayout.getHeight();
我的問題是,所有的ID我可以找到我R.id
都是按鈕,文本的意見,以及所有這類。根本沒有佈局ID!
然後我試着寫:
relativeLayout = (RelativeLayout) findViewById(R.layout.main_activity);
relativeLayout
爲空時運行。所以這也是不正確的。
是否需要手動添加布局ID到R.id
?我不這麼認爲。
但爲什麼在R.id
中沒有編號的編號?
http://stackoverflow.com/questions/7899806/get-layout-from-view可能對你有幫助 – 2013-07-15 03:10:39
活動XML例如在RelativeLayout中的main.xml放置一個像這樣的id android:id =「@ + id/ui_main_holder_relative」 – Arslan
你可以粘貼包含你的'RelativeLayout'的佈局xml嗎? – Geobits