I am not getting clear about the concept of getPreferredWidth() and getPreferredHeight() methods. What do they return means on what what basis the values are 开发者_JAVA技巧returned.??
What is difference between getWidth() and getPreferredWidth()???
Thank you..
By default, Field#getPreferredHeight() and Field#getPreferredWidth() return 0. They're there for your custom Fields to override with whatever your custom Field's preferred width/height is.
The value you supply in your overridden methods is then taken into consideration when it comes to laying out your Field. If your preferred values are suitable for the display area and your Field's content, then your preferred values will be used. These values are just suggestions.
Field#getHeight() and Field#getWidth() on the other hand return the actual extent of the Field.
Field#getPreferredWidth() is used to determine width of the specific field when it is created. You need to override this method if you want to create some customization. Display#getWidth() returns the physical screen size of your device or simulator which you can use to create buttons relative to the screen width. Field#getWidth() returns the actual width of your field that you created earlier. I used that code block to create a button which fills whole screen width and with default height.
This is how you override the getPreferredWidth()
method for a specific field i.e. ButtonField.
ButtonField myButton = new ButtonField("Click", USE_ALL_WIDTH){
public int getPreferredWidth(){
return Display.getWidth();
}
};
精彩评论