java.lang.Object | |
↳ | com.neomades.ui.View |
![]() |
![]() |
Abstract UI element (View).
Important : You must not override a View in order to customize an UI element.
Stretch mode
Each view could manage its size belong the content
or the parent.
The setStretchMode()
method could use :
MATCH_CONTENT
: the
size will cover the content of the viewMATCH_PARENT
: the size
will cover more than the content of the view
A parent with MATCH_CONTENT
which contains
a child with MATCH_PARENT
will have the same
dimension as the child (like the child in MATCH_CONTENT mode).
Dimensioning
The Generic API enables to set the dimensions of
each view (width, height, margin, padding). The dimensions must be set in DP
(density independent pixel). It represents a virtual pixel unit that you must
use to express dimensions or positions in a density-independent way.
Layout Alignment
A Layout could contains many views, each of
these views could manage its alignment from the layout.
Content Alignment
Some of view (eg.
Button
) have content that can be aligned
XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Attribute Name | Related Method | Description | |||||||||
background | setBackground(int) | Res.background.XXXX | |||||||||
backgroundColor | setBackgroundColor(Color) | #AARRGGBB or a color | |||||||||
backgroundImage | setBackgroundImage(Image) | Res.image.XXXX or a color | |||||||||
borderColor | setBorderColor(Color) | #AARRGGBB or a color | |||||||||
borderWidth | setBorderWidth(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
clickable | setClickable(boolean) | If the view could be clicked | |||||||||
cornerRadius | setCornerRadius(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
enabled | setEnabled(boolean) | If the view could be enabled | |||||||||
focusable | setFocusable(boolean) | If the view could be focused | |||||||||
height | setHeight(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
id | setId(int) | Res.id.XXXX | |||||||||
layoutAlignment | setLayoutAlignment(int) | A combination of alignment values (eg: TOP|LEFT) | |||||||||
margin | setMargin(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
marginBottom | setMarginBottom(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
marginLeft | setMarginLeft(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
marginRight | setMarginRight(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
marginTop | setMarginTop(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
padding | setPadding(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
paddingBottom | setPaddingBottom(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
paddingLeft | setPaddingLeft(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
paddingRight | setPaddingRight(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
paddingTop | setPaddingTop(int) | eg: 10dp or 10 (dp is the default unit) | |||||||||
stretchHorizontalMode | setStretchHorizontalMode(int) | The dimension could be adapted to the parent dimension or to the content size. | |||||||||
stretchVerticalMode | setStretchVerticalMode(int) | The dimension could be adapted to the parent dimension or to the content size. | |||||||||
visible | setVisible(boolean) | If the view is visible or hidden and collapsed | |||||||||
width | setWidth(int) | eg: 10dp or 10 (dp is the default unit) |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
View()
Internal
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
View |
findView(int viewId)
Find view by Id.
| ||||||||||
int |
getId()
Returns the identifier of this element, by default all elements return "0".
| ||||||||||
Object |
getTag()
Returns this view's tag.
| ||||||||||
static View |
inflateXML(int layoutResId)
Inflate view from XMLLayout declared in the URS File.
| ||||||||||
static View |
inflateXML(InputStream xmlStream)
@return
| ||||||||||
boolean |
isClickable()
Returns if the view is clickable.
| ||||||||||
boolean |
isEnabled()
Return a boolean indicating if the view is enabled or not
| ||||||||||
boolean |
isFocusable()
Returns if the view is focusable (for the devices that have a keyboard Ui
navigation).
| ||||||||||
boolean |
isVisible()
Returns if the view is visible
| ||||||||||
void |
runOnUiThread(Runnable action)
Calls
action.run() asynchronously on the UI-Thread . | ||||||||||
void |
setBackground(Background background)
Sets the background on this view.
| ||||||||||
void |
setBackground(int backgroundResId)
Sets the background on this view with a XML background definition.
| ||||||||||
void |
setBackgroundColor(Color color)
Sets the background color on this view.
| ||||||||||
void |
setBackgroundImage(int imageID)
Set the background image for this view.
| ||||||||||
void |
setBackgroundImage(Image image)
Set the background image for this view.
| ||||||||||
void |
setBorderColor(Color borderColor)
Sets the border color on this view.
| ||||||||||
void |
setBorderWidth(int widthInDp)
Set the border width (size) in DP units.
| ||||||||||
void |
setClickListener(ClickListener clickListener)
Sets a ClickListener to this view.
| ||||||||||
void |
setClickable(boolean clickable)
Sets this view clickable.
| ||||||||||
void |
setCornerRadius(int radiusSize)
Set the four corners radius, if the view has corners.
| ||||||||||
void |
setDrawingCacheEnabled(boolean enabled)
Enables or disables the drawing cache.
| ||||||||||
void |
setEnabled(boolean enabled)
Sets the state of this view to enabled or disabled.
| ||||||||||
void |
setFocusable(boolean focusable)
Sets the view focusable.
| ||||||||||
void |
setGestureDetector(GestureDetector detector)
Sets a
GestureDetector on this view. | ||||||||||
void |
setHeight(int heightDp)
Sets the height of the view, in dp units (density-independent pixels).
| ||||||||||
void |
setId(int id)
Sets a identifier/tag to this element
| ||||||||||
void |
setInvalidateDisabled(boolean disabled)
If set to true, force the layout that contains the view to not be draw again
when its content changes.
| ||||||||||
void |
setLayoutAlignment(int alignment)
Sets the view alignment into its parent.
| ||||||||||
void |
setMargin(int uniformMarginDp)
Set the margin outside this view (used by
Layout ), by setting on each
side the given value. | ||||||||||
void |
setMargin(int leftDp, int topDp, int rightDp, int bottomDp)
Set the margin outside this view (used by
Layout ). | ||||||||||
void |
setMarginBottom(int marginBottomDp)
Sets the bottom margin with the given value.
| ||||||||||
void |
setMarginLeft(int marginLeftDp)
Sets the left margin with the given value.
| ||||||||||
void |
setMarginRight(int marginRightDp)
Sets the right margin with the given value.
| ||||||||||
void |
setMarginTop(int marginTopDp)
Sets the top margin with the given value.
| ||||||||||
void |
setPadding(int leftDp, int topDp, int rightDp, int bottomDp)
Sets the view padding.
| ||||||||||
void |
setPadding(int uniformPaddingDp)
Sets the view padding, with for each side the value given in parameter.
| ||||||||||
void |
setPaddingBottom(int paddingBottomDp)
Sets the bottom padding with the given value.
| ||||||||||
void |
setPaddingLeft(int paddingLeftDp)
Sets the left padding with the given value.
| ||||||||||
void |
setPaddingRight(int paddingRightDp)
Sets the right padding with the given value.
| ||||||||||
void |
setPaddingTop(int paddingTopDp)
Sets the top padding with the given value.
| ||||||||||
void |
setSize(int widthDp, int heightDp)
Sets the size of the view, in dp units (density-independent pixels).
| ||||||||||
void |
setStretchHorizontalMode(int widthMode)
Sets the stretch horizontal mode.
| ||||||||||
void |
setStretchMode(int horizontalMode, int verticalMode)
Sets the view content stretch mode.
| ||||||||||
void |
setStretchVerticalMode(int heightMode)
Sets the stretch vertical mode.
| ||||||||||
void | setStyle(int styleResId) | ||||||||||
void | setStyle(Style style) | ||||||||||
void |
setTag(Object tag)
Sets the tag associated with this view.
| ||||||||||
void |
setTouchListener(TouchListener touchListener)
Register a listener to be invoked when a touch event is dispatched to this
view.
| ||||||||||
void |
setTransformOrigin(float xOrigin, float yOrigin)
Sets the x and y location of the point around which the view will be scaled
or rotated when an animation occurs.
| ||||||||||
void |
setVisible(boolean visible)
Sets the view's visibility : visible or invisible/hidden
| ||||||||||
void |
setWidth(int widthDp)
Sets the width of the view, in dp units (density-independent pixels).
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
A combination of alignment values (eg: TOP|LEFT)
The dimension could be adapted to the parent dimension or to the content size. View's size is prior than stretch mode.
The dimension could be adapted to the parent dimension or to the content size. View's size is prior than stretch mode.
Internal
Find view by Id.
viewId | the view with the Id |
---|
Returns the identifier of this element, by default all elements return "0".
Returns this view's tag.
Inflate view from XMLLayout declared in the URS File.
layoutResId | layout resId from the Resources class |
---|
ResourceNotFoundException | if the layout has not been found |
---|---|
CrossThreadException | if the method is called from outside the UI-Thread |
@return
ResourceNotFoundException | |
CrossThreadException | |
ResourceNotFoundException |
Returns if the view is clickable.
Some views are not clickable (see the specific view documentation in order to know if the view clickable property could be changed)
Return a boolean indicating if the view is enabled or not
Returns if the view is focusable (for the devices that have a keyboard Ui navigation).
For other platforms or devices, this method will always return false.
Calls action.run()
asynchronously on the UI-Thread
.
This method should be used when an application thread needs to update the
GUI.
If already on the UI-Thread
, the Runnable
is run
immediately.
action | the action to execute in the UI-Thread
|
---|
Sets the background on this view.
background | the new background or null to set the default platform background |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the background on this view with a XML background definition.
backgroundResId | resource identifier from Res |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the background color on this view. To reset the native default
background, use setBackground(Background)
with null
.
color | the color to set |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|---|
NullPointerException | if the color parameter is null |
Set the background image for this view.
If the size of the image is different than the view size, then the image will be stretched in order to fill the view's background.
imageID | the id of the image to use for the background |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Set the background image for this view.
If the size of the image is different than the view size, then the image will be stretched in order to fill the view's background.
To reset the native default background, use
setBackground(Background)
with null
.
image | the image to use for the background (null to remove the current image) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|---|
NullPointerException | if the image parameter is null |
Sets the border color on this view.
borderColor | the new color or null to set the default platform color |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Set the border width (size) in DP units.
To disable border, the border width should be set to zero.
widthInDp | width of the border in DP units |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets a ClickListener to this view.
When the view is clicked, the onClick()
method from ClickListener
will be called, with the clicked view as
parameter.
If the view is not clickable, it becomes clickable (even if the listener is
null
).
clickListener | The listener to set on the view (or null to remove the current listener) |
---|
Sets this view clickable.
clickable | true if the view should be clickable |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Set the four corners radius, if the view has corners. The value of the radius must be set in dp.
To disable corners radius, the radius size should be set to zero.
radiusSize | radius of the corner in dp |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Enables or disables the drawing cache.
enabled | true to enable the drawing cache, false otherwise |
---|
Sets the state of this view to enabled or disabled.
enabled | true if the View is enabled |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the view focusable.
(Only available for the devices that have a keyboard UI navigation)
focusable | true if the view is focusable |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets a GestureDetector
on this view. A same
GestureDetector
can be reused on multiple views.
detector | the detector, or null to remove the previously set detector |
---|
Sets the height of the view, in dp units (density-independent pixels). Note that if a height is set, vertical content stretch mode is ignored.
The height is prior than the vertical stretch mode : if the view is in MATCH_PARENT vertically but with a fixed height, then the height will be used.
heightDp | the height to set in dp |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets a identifier/tag to this element
id | the identifier |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
If set to true, force the layout that contains the view to not be draw again when its content changes. The view will be redraw with its new content but its layout will not be recalculated. Consequently if the content is too large or too small for the view, it may result in a undesirable display. This behavior allows you to ignore layout updates, which is usually better for performance.
Be sure to reset it to false to activate again the default behavior.
disabled | activate / deactivate the automatic calculation and drawing of the layout's view |
---|
Sets the view alignment into its parent.
If the stretch mode is not MATCH_PARENT
, then the
layout alignment could set the alignment
of this view into its
parent. If the stretch mode is MATCH_PARENT
, the layout
alignment is not taken into account until the stretch mode is set to
MATCH_CONTENT
e.g. A button with MATCH_CONTENT
in
widthMode
and inserted into a VerticalLayout
could
alignement into the layout on the LEFT
, HCENTER
or
RIGHT
If this view is into VerticalLayout
, then the layout alignment will
have effect only for horizontal alignment. To align this view vertically, see
the setContentAlignment(int)
method and the conditions
to align vertically a child in a VerticalLayout
.
If this view is into HorizontalLayout
, then the layout alignment will
have effect only for vertical alignment. To align this view horizontally, see
the setContentAlignment(int)
method and the conditions
to align horizontally a child in a HorizontalLayout
.
Layout
alignment | alignment of this in relation with its parent (Layout ) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Set the margin outside this view (used by Layout
), by setting on each
side the given value.
Cross-Platform consideration
In Android, be sure to apply a layout alignment to the view if it is a
LinearLayout
. If not, the margin may not apply.
uniformMarginDp | the margin to set on each side (in dp). |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Set the margin outside this view (used by Layout
).
Cross-Platform consideration
In Android, be sure to apply a layout alignment to the view if it is a
LinearLayout
. If not, the margin may not apply.
leftDp | value of the left margin (in dp) |
---|---|
topDp | value of the top margin (in dp) |
rightDp | value of the right margin (in dp) |
bottomDp | value of the bottom margin (in dp) |
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the bottom margin with the given value.
Cross-Platform consideration
In Android, be sure to apply a layout alignment to the view if it is a
LinearLayout
. If not, the margin may not apply.
marginBottomDp | value of the bottom margin (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the left margin with the given value.
Cross-Platform consideration
In Android, be sure to apply a layout alignment to the view if it is a
LinearLayout
. If not, the margin may not apply.
marginLeftDp | value of the left margin (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the right margin with the given value.
Cross-Platform consideration
In Android, be sure to apply a layout alignment to the view if it is a
LinearLayout
. If not, the margin may not apply.
marginRightDp | value of the right margin (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the top margin with the given value.
Cross-Platform consideration
In Android, be sure to apply a layout alignment to the view if it is a
LinearLayout
. If not, the margin may not apply.
marginTopDp | value of the top margin (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the view padding.
leftDp | the left padding (in dp) |
---|---|
topDp | the top padding (in dp) |
rightDp | the right padding (in dp) |
bottomDp | the bottom padding (in dp) |
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the view padding, with for each side the value given in parameter.
uniformPaddingDp | the padding to set on each side (in dp). |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the bottom padding with the given value.
paddingBottomDp | value of the bottom padding (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the left padding with the given value.
paddingLeftDp | value of the left padding (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the right padding with the given value.
paddingRightDp | value of the right padding (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the top padding with the given value.
paddingTopDp | value of the top padding (in dp) |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the size of the view, in dp units (density-independent pixels). Note that if a size is set, vertical and horizontal content stretch mode are ignored.
The size is prior than the stretch mode : if the view is in MATCH_PARENT but with a fixed size, then the size will be used.
widthDp | the width to set in dp |
---|---|
heightDp | the height to set in dp |
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the stretch horizontal mode.
widthMode | MATCH_PARENT or MATCH_CONTENT |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|---|
IllegalArgumentException | If the widthMode parameter has wrong value |
Sets the view content stretch mode.
A view could arrange its size :
horizontalMode | MATCH_PARENT or MATCH_CONTENT |
---|---|
verticalMode | MATCH_PARENT or MATCH_CONTENT |
CrossThreadException | if the method is called from outside the UI-Thread |
---|---|
IllegalArgumentException | if any of mode parameters has wrong value |
Sets the stretch vertical mode.
heightMode | MATCH_PARENT or MATCH_CONTENT |
---|
IllegalArgumentException | If the heightMode parameter has wrong value |
---|
Sets the tag associated with this view.
A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a view without resorting to another data structure.
tag | an Object to tag the view with |
---|
Register a listener to be invoked when a touch event is dispatched to this view.
If the parameter is null, the previous listener, if exist, will be removed.
touchListener | the touch listener to attach to this view |
---|
Sets the x and y location of the point around which the view will be scaled or rotated when an animation occurs.
By default, the point is centered on the object. X and Y must be values between 0 and 1 where (0, 0) represents the top left corner of the view and (1, 1) the bottom right corner. The center of the view is (0.5, 0.5).
xOrigin | x location of the scale and rotation center |
---|---|
yOrigin | y location of the scale and rotation center |
IllegalArgumentException | if x or y are not between 0 and 1. |
---|
Sets the view's visibility : visible or invisible/hidden
visible | true if the view should be visible |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|
Sets the width of the view, in dp units (density-independent pixels). Note that if a width is set, horizontal content stretch mode is ignored.
The width is prioritary over the stretch mode : if the view is in MATCH_PARENT horizontally but with a fixed width, then the width will be used.
widthDp | the width to set in dp |
---|
CrossThreadException | if the method is called from outside the UI-Thread |
---|