Zum Inhalt springen

Android Training/Supporting Different Screens: Unterschied zwischen den Versionen

keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
<languages />
<translate>
Android categorizes device screens using two general properties: size and density. You should expect that your app will be installed on devices with screens that range in both size and density. As such, you should include some alternative resources that optimize your app’s appearance for different screen sizes and densities.
Android categorizes device screens using two general properties: size and density. You should expect that your app will be installed on devices with screens that range in both size and density. As such, you should include some alternative resources that optimize your app’s appearance for different screen sizes and densities.
* There are four generalized sizes: small, normal, large, xlarge
* There are four generalized sizes: small, normal, large, xlarge
Zeile 11: Zeile 13:
'''Note:''' Android automatically scales your layout in order to properly fit the screen. Thus, your layouts for different screen sizes don't need to worry about the absolute size of UI elements but instead focus on the layout structure that affects the user experience (such as the size or position of important views relative to sibling views).
'''Note:''' Android automatically scales your layout in order to properly fit the screen. Thus, your layouts for different screen sizes don't need to worry about the absolute size of UI elements but instead focus on the layout structure that affects the user experience (such as the size or position of important views relative to sibling views).


For example, this project includes a default layout and an alternative layout for ''large'' screens:<syntaxhighlight lang="text">
For example, this project includes a default layout and an alternative layout for ''large'' screens:</translate>
<syntaxhighlight lang="text">
MyProject/
MyProject/
     res/
     res/
Zeile 18: Zeile 21:
         layout-large/
         layout-large/
             main.xml
             main.xml
</syntaxhighlight>The file names must be exactly the same, but their contents are different in order to provide an optimized UI for the corresponding screen size.
</syntaxhighlight>


Simply reference the layout file in your app as usual:<syntaxhighlight lang="java">
<translate>The file names must be exactly the same, but their contents are different in order to provide an optimized UI for the corresponding screen size.
 
Simply reference the layout file in your app as usual:</translate>
<syntaxhighlight lang="java">
@Override
@Override
  protected void onCreate(Bundle savedInstanceState) {
  protected void onCreate(Bundle savedInstanceState) {
Zeile 26: Zeile 32:
     setContentView(R.layout.main);
     setContentView(R.layout.main);
}
}
</syntaxhighlight>The system loads the layout file from the appropriate layout directory based on screen size of the device on which your app is running. More information about how Android selects the appropriate resource is available in the [http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch Providing Resources] guide.
</syntaxhighlight>


As another example, here's a project with an alternative layout for landscape orientation:<syntaxhighlight lang="text">
<translate>The system loads the layout file from the appropriate layout directory based on screen size of the device on which your app is running. More information about how Android selects the appropriate resource is available in the [http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch Providing Resources] guide.
 
As another example, here's a project with an alternative layout for landscape orientation:</translate>
<syntaxhighlight lang="text">
MyProject/
MyProject/
     res/
     res/
Zeile 35: Zeile 44:
         layout-land/
         layout-land/
             main.xml
             main.xml
</syntaxhighlight>By default, the <code>layout/main.xml</code> file is used for portrait orientation.
</syntaxhighlight>
 
<translate>By default, the <code>layout/main.xml</code> file is used for portrait orientation.


If you want to provide a special layout for landscape, including while on large screens, then you need to use both the <code>large</code> and <code>land</code> qualifier:<syntaxhighlight lang="text">
If you want to provide a special layout for landscape, including while on large screens, then you need to use both the <code>large</code> and <code>land</code> qualifier:</translate>
<syntaxhighlight lang="text">
MyProject/
MyProject/
     res/
     res/
Zeile 48: Zeile 60:
         layout-large-land/  # large landscape
         layout-large-land/  # large landscape
             main.xml
             main.xml
</syntaxhighlight>'''Note:''' Android 3.2 and above supports an advanced method of defining screen sizes that allows you to specify resources for screen sizes based on the minimum width and height in terms of density-independent pixels. This lesson does not cover this new technique. For more information, read [http://developer.android.com/training/multiscreen/index.html Designing for Multiple Screens].
</syntaxhighlight>
 
<translate>'''Note:''' Android 3.2 and above supports an advanced method of defining screen sizes that allows you to specify resources for screen sizes based on the minimum width and height in terms of density-independent pixels. This lesson does not cover this new technique. For more information, read [http://developer.android.com/training/multiscreen/index.html Designing for Multiple Screens].


== Create Different Bitmaps ==
== Create Different Bitmaps ==
Zeile 60: Zeile 74:
This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.
This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.


Then, place the files in the appropriate drawable resource directory:<syntaxhighlight lang="text">
Then, place the files in the appropriate drawable resource directory:</translate>
<syntaxhighlight lang="text">
MyProject/
MyProject/
     res/
     res/
Zeile 71: Zeile 86:
         drawable-ldpi/
         drawable-ldpi/
             awesomeimage.png
             awesomeimage.png
</syntaxhighlight>Any time you reference <code>@drawable/awesomeimage</code>, the system selects the appropriate bitmap based on the screen's density.
</syntaxhighlight>
 
<translate>Any time you reference <code>@drawable/awesomeimage</code>, the system selects the appropriate bitmap based on the screen's density.


'''Note:''' Low-density (ldpi) resources aren’t always necessary. When you provide hdpi assets, the system scales them down by one half to properly fit ldpi screens.
'''Note:''' Low-density (ldpi) resources aren’t always necessary. When you provide hdpi assets, the system scales them down by one half to properly fit ldpi screens.


For more tips and guidelines about creating icon assets for your app, see the [http://developer.android.com/design/style/iconography.html Iconography design guide].
For more tips and guidelines about creating icon assets for your app, see the [http://developer.android.com/design/style/iconography.html Iconography design guide].
</translate>
{{TNT|Android Training/Attribution}}
11.008

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.