Changes

Jump to: navigation, search

Creating an Android User Interface in Java Code

6 bytes added, 21:08, 1 February 2016
m
Text replacement - "<google>BUY_ANDROID</google>" to "<htmlet>androidstudio</htmlet>"
<googlehtmlet>BUY_ANDROIDandroidstudio</googlehtmlet>
So far in this tutorial it has not been necessary to use view IDs. In order to demonstrate the use of IDs in Java code, the example will now be extended to add another view in the form of an EditText view that will be configured to be aligned 80 pixels above the existing button and centered horizontally. The following code modifications add the new view to the activity and then set IDs of 1 and 2 on the Button and EditText views respectively. Layout parameters are then created for the EditText view so that it is aligned with the button (note the call to getId() on the button to get the view ID) and centered horizontally within the layout. Finally, the margins property of the EditText field is configured to set the bottom margin to 80 pixels before adding the new view to parent layout:
<googlehtmlet>BUY_ANDROIDandroidstudio</googlehtmlet>
<pre>
<googlehtmlet>BUY_ANDROIDandroidstudio</googlehtmlet>

Navigation menu