2016-01-21 69 views
0

我開發Android工作室使用intellij插件,我想組件尺寸(按鈕或TextView的的寬度,高度)在intellij插件。如何獲得機器人工作室組件(按鈕,文本等...),大小(寬度,高度或默認大小)

enter image description here

在圖片中,我寫的代碼height="wrap_content"和寬度"wrap_content"

我想知道,按鈕大小(DP或PX號)。

而且當textview或另一組件被定義wrap_content,不知寬度和高度。

我想,android studio組件具有默認的寬度和高度。但我不知道它在哪裏定義!

謝謝!

+0

我認爲你正在製作一個應用程序。 – Rohit5k2

+0

我做了應用程序,但現在我開發android studio插件,所以我想知道組件的默認大小 –

回答

0

android:minHeight屬性的默認大小設置48dip默認。

看一看:http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html

WRAP_CONTENT,意味着視圖想要剛好足夠大到 附上其內容(加墊)

而且當然:https://stackoverflow.com/a/23984754/4409113

+0

48dp是組件的默認高度和寬度? –

+0

我認爲這隻適用於那些擁有'android:minHeight'屬性的組件。所以,我想是的。但是您可能想用getHeigh()和getWidth嘗試它,然後將它用於您的porpuse。 – Mohsen

+1

現在我檢查按鈕的默認大小,默認寬度爲88dp,默認高度爲48dp ...和文本查看默認寬度爲27dp,高度爲16DP ...(剛剛定義的文本...) 我不知道默認定義! –

0

爲了讓Button寬度高度使用此代碼。(在onCreate方法使用此代碼)

Button customButton= (Button) findViewById(R.id.customButton); 
customButton.post(new Runnable() { 
     @Override 
     public void run() { 
     Log.e("Button", "Width = "customButton.getWidth() + " Height = " + customButton.getHeight()); 
     } 
}); 

getWidth()getHeight()回報Button寬度高度px

+0

謝謝你,但這段代碼是在Android應用程序工作室.... 我想知道組件的默認大小隻是項目文件,所以我使用這個信息intellij插件 –

相關問題