Zum Inhalt springen

Android Training/Building a Simple User Interface/en: Unterschied zwischen den Versionen

Neue Version von externer Quelle importiert
(Übernehme Bearbeitung einer neuen Version der Quellseite)
(Neue Version von externer Quelle importiert)
 
(8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
<languages />
<languages/>
[[Datei:Viewgroup.png|thumb|Illustration of how ViewGroup objects form branches in the layout and contain View objects.]]
[[Datei:Viewgroup.png|thumb|Illustration of how ViewGroup objects form branches in the layout and contain View objects.]]
In this lesson, you create a layout in XML that includes a text field and a button. In the next lesson, your app responds when the button is pressed by sending the content of the text field to another activity.
In this lesson, you create a layout in XML that includes a text field and a button. In the next lesson, your app responds when the button is pressed by sending the content of the text field to another activity.


The graphical user interface for an Android app is built using a hierarchy of View and ViewGroup objects. View objects are usually UI widgets such as buttons or text fields. ViewGroup objects are invisible view containers that define how the child views are laid out, such as in a grid or a vertical list.
The graphical user interface for an Android app is built using a hierarchy of <code>View</code> and <code>ViewGroup</code> objects. <code>View</code> objects are usually UI widgets such as buttons or text fields. <code>ViewGroup</code> objects are invisible view containers that define how the child views are laid out, such as in a grid or a vertical list.


Android provides an XML vocabulary that corresponds to the subclasses of View and ViewGroup so you can define your UI in XML using a hierarchy of UI elements.
Android provides an XML vocabulary that corresponds to the subclasses of <code>View</code> and <code>ViewGroup</code> so you can define your UI in XML using a hierarchy of UI elements.


Layouts are subclasses of the ViewGroup. In this exercise, you'll work with a LinearLayout.
<code>Layouts</code> are subclasses of the <code>ViewGroup</code>. In this exercise, you'll work with a <code>LinearLayout</code>.


== Create a Linear Layout ==
== Create a Linear Layout ==
Zeile 139: Zeile 139:
To improve the layout efficiency when you specify the weight, you should change the width of the <code>EditText</code> to be zero (0dp). Setting the width to zero improves layout performance because using <code>"wrap_content"</code> as the width requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.
To improve the layout efficiency when you specify the weight, you should change the width of the <code>EditText</code> to be zero (0dp). Setting the width to zero improves layout performance because using <code>"wrap_content"</code> as the width requires the system to calculate a width that is ultimately irrelevant because the weight value requires another width calculation to fill the remaining space.


Here’s how your complete activity_my.xmllayout file should now look:
Here’s how your complete <code>activity_my.xml</code> layout file should now look:
''res/layout/activity_my.xml''
''res/layout/activity_my.xml''
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
Zeile 163: Zeile 163:
This layout is applied by the default <code>Activity</code> class that the SDK tools generated when you created the project. Run the app to see the results:
This layout is applied by the default <code>Activity</code> class that the SDK tools generated when you created the project. Run the app to see the results:


# In Android Studio, from the toolbar, click Run .
# In Android Studio, from the toolbar, click '''Run'''.
# Or from a command line, change directories to the root of your Android project and execute:
# Or from a command line, change directories to the root of your Android project and execute:
#: <code>ant debug</code>
#: <code>ant debug</code>
#: <code>adb install bin/MyFirstApp-debug.apk</code>
#: <code>adb install bin/MyFirstApp-debug.apk</code>
Continue to the next lesson to learn how to respond to button presses, read content from the text field, start another activity, and more.
Continue to the next lesson to learn how to respond to button presses, read content from the text field, start another activity, and more.


{{Android Training/ Vorlage:Attribution}}
{{TNT|Android Training/Attribution}}
372

Bearbeitungen

Cookies helfen uns bei der Bereitstellung von Android Wiki. Durch die Nutzung von Android Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.