A bitmap file is a. The following application code retrieves the image as a Drawable :. The effect is an alias for a raw bitmap file. The XML can specify additional properties for the bitmap such as dithering and tiling. A NinePatch is a PNG image in which you can define stretchable regions that Android scales when content within the View exceeds the normal image bounds. An example use of a Nine-Patch image is the background used by Android's standard Button widget, which must stretch to accommodate the text or image inside the button.
Same as with a normal bitmap , you can reference a Nine-Patch file directly or from a resource defined by XML. For a complete discussion about how to create a Nine-Patch file with stretchable regions, see the 2D Graphics document. The XML can specify dithering for the image. A LayerDrawable is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top.
All drawable items are scaled to fit the size of the containing View, by default. Thus, placing your images in a layer list at different positions might increase the size of the View and some images scale as appropriate. This ensures that none of the images are scaled to fit the size of the container, due to resizing caused by the offset images. A StateListDrawable is a drawable object defined in XML that uses a several different images to represent the same graphic, depending on the state of the object.
For example, a Button widget can exist in one of several different states pressed, focused, or neither and, using a state list drawable, you can provide a different background image for each state. You can describe the state list in an XML file. During each state change, the state list is traversed top to bottom and the first item that matches the current state is used—the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.
Note: Remember that Android applies the first item in the state list that matches the current state of the object. So, if the first item in the list contains none of the state attributes above, then it is applied every time, which is why your default value should always be last as demonstrated in the following example. A Drawable that manages a number of alternate Drawables, each assigned a maximum numerical value.
Setting the level value of the drawable with setLevel loads the drawable resource in the level list that has a android:maxLevel value greater than or equal to the value passed to the method. Once this is applied to a View , the level can be changed with setLevel or setImageLevel.
A TransitionDrawable is a drawable object that can cross-fade between the two drawable resources. No more than two items are supported. To transition forward, call startTransition. To transition backward, call reverseTransition. A drawable defined in XML that insets another drawable by a specified distance. This is useful when a View needs a background that is smaller than the View's actual bounds. A drawable defined in XML that clips another drawable based on this Drawable's current level.
You can control how much the child drawable gets clipped in width and height based on the level, as well as a gravity to control where it is placed in its overall container. Most often used to implement things like progress bars. The following code gets the drawable and increases the amount of clipping in order to progressively reveal the image:.
Increasing the level reduces the amount of clipping and slowly reveals the image. Here it is at a level of Note: The default level is 0, which is fully clipped so the image is not visible. When the level is 10,, the image is not clipped and completely visible. Note: Every corner must initially be provided a corner radius greater than 1, or else no corners are rounded.
If you want specific corners to not be rounded, a work-around is to use android:radius to set a default corner radius greater than 1, but then override each and every corner with the values you really want, providing zero "0dp" where you don't want rounded corners. Note: The shape scales to the size of the container View proportionate to the dimensions defined here, by default.
When you use the shape in an ImageView , you can restrict scaling by setting the android:scaleType to "center". Content and code samples on this page are subject to the licenses described in the Content License. App Basics. Build your first app. App resources. Resource types. App manifest file.
Device compatibility. Multiple APK support. Tablets, large screens, and foldables. Build responsive UIs. Build for foldables. Getting started. Handling data. User input. Watch Face Studio. Health services. Creating watch faces. Android TV. Build TV Apps. Build TV playback apps. Help users find content on TV. Recommend TV content. Watch Next. Build TV games. Build TV input services.
TV Accessibility. Android for Cars. Build media apps for cars. Build navigation, parking, and charging apps for cars. Android Things. Supported hardware. Advanced setup. Build apps. Create a Things app. Communicate with wireless devices. Configure devices. Interact with peripherals. Build user-space drivers.
Manage devices. Create a build. Push an update. Chrome OS devices. App architecture. Architecture Components. UI layer libraries. View binding. Data binding library. Lifecycle-aware components. Paging Library.
Paging 2. Data layer libraries. How-To Guides. Advanced Concepts. Threading in WorkManager. App entry points. App shortcuts. App navigation. Navigation component. App links. Dependency injection. Core topics. App compatibility. Interact with other apps. Package visibility. Intents and intent filters.
User interface. Add motion to your layout with MotionLayout. MotionLayout XML reference. Improving layout performance. Custom view components. Look and feel. Splash screens. Add the app bar. Control the system UI visibility. Supporting swipe-to-refresh. Pop-up messages overview. Adding search functionality. Creating backward-compatible UIs. Home channels for mobile apps. App widgets. Media app architecture. Building an audio app. Building a video app. The Google Assistant. Routing between devices.
Background tasks. Manage device awake state. Save to shared storage. Save data in a local database. Sharing simple data. Sharing files. If you see errors, you need to make sure that the imported vector drawable renders properly.
Scroll through the list to view the errors. In a layout file, you can set any icon-related widget, such as ImageButton , ImageView , and so on, to point to a vector drawable. For example, the following layout shows a vector drawable displayed on a button:.
Figure 4. A vector drawable displayed on a button in a layout. Click the Design tab to display the Layout Editor.
In the Resources dialog, select Drawable in the left pane, and then select the vector drawable you imported. Click OK. The vector drawable appears on the ImageButton in the layout.
If the project uses the Support Library, the ImageButton code should be similar to the following:. You can normally refer to a vector drawable resource in a generic way in your code, and when your app runs, the corresponding vector or raster image displays automatically depending on the API level:. The following Java code retrieves the image as a Drawable :.
The getResources method resides in the Context class, which applies to UI objects, such as activities, fragments, layouts, views, and so on. For the Support Library technique, you must use coding techniques that are compatible with the Support Library. However, we don't recommend it. If you add code that's not supported on Android 4. You also need to make sure that the manifest contains the code to support your changes.
Figure 5. Remember that the generated PNGs could display differently in the Preview window than in the app due to different rendering engines and any changes made to the vector drawable before a build.
As a result, when you add code, you should always check that the generated PNGs match the vector drawable. To do so, you could double-click the PNG in the Project Files view of the Project window; the left margin of the Code Editor also displays the PNG image when your code refers to the drawable, as shown in figure 6.
Figure 6. Android Studio deletes the file from the project and the drive. However, if you chose to search for places in the project where the file is used and some usages are found, you can view them and decide whether to delete the file. Any auto-generated PNG and XML files corresponding to the deleted vector drawable are removed from the project and the drive. When your minimum API level includes Android 4.
The following list summarizes supported and unsupported PSD characteristics, as well as some conversion details. The following section summarizes supported and unsupported features when the tool converts an SVG file to a VectorDrawable , along with additional conversion details. VectorDrawable supports SVG paths. The tool converts primitive shapes such as circles, squares, and polygons to paths. The tool supports group elements for translation, scaling, and rotation.
Groups do not support an opacity property. Paths can be filled and stroked using solid colors or gradients linear, radial, or angular. Only centered strokes are supported. Blend modes are not supported. Dashed paths are not supported. Any feature not listed in the Supported features section above is unsupported. Notable unsupported features include the following:. Content and code samples on this page are subject to the licenses described in the Content License. Android Studio.
Download What's new User guide Preview. Meet Android Studio. Manage your project. Write your app. Build and run your app. Run apps on the emulator. Run apps on a hardware device. Configure your build. Optimize your build speed. Debug your app. Test your app. Profile your app. Android Studio profilers.
0コメント