Card View

  • Upload
    vkm2013

  • View
    217

  • Download
    0

Embed Size (px)

DESCRIPTION

CardView uses elevation property on L for shadows and falls back to a custom shadow implementation on older platforms.

Citation preview

CardViewClass Overview

A FrameLayout with a rounded corner background and shadow.CardView useselevationproperty on L for shadows and falls back to a custom shadow implementation on older platforms.Due to expensive nature of rounded corner clipping, on platforms before L, CardView does not clip its children that intersect with rounded corners. Instead, it adds padding to avoid such intersection (SeesetPreventCornerOverlap(boolean)to change this behavior).Before L, CardView adds padding to its content and draws shadows to that area. This padding amount is equal tomaxCardElevation + (1 - cos45) * cornerRadiuson the sides andmaxCardElevation * 1.5 + (1 - cos45) * cornerRadiuson top and bottom.Since padding is used to offset content for shadows, you cannot set padding on CardView. Instead, you can use content padding attributes in XML orsetContentPadding(int, int, int, int)in code to set the padding between the edges of the Card and children of CardView.Note that, if you specify exact dimensions for the CardView, because of the shadows, its content area will be different between platforms before L and after L. By using api version specific resource values, you can avoid these changes. Alternatively, If you want CardView to add inner padding on platforms L and after as well, you can setsetUseCompatPadding(boolean)totrue.To change CardView's elevation in a backward compatible way, usesetCardElevation(float). CardView will use elevation API on L and before L, it will change the shadow size. To avoid moving the View while shadow size is changing, shadow size is clamped bygetMaxCardElevation(). If you want to change elevation dynamically, you should callsetMaxCardElevation(float)when CardView is initialized.Create CardsCardViewextends theFrameLayoutclass and lets you show information inside cards that have a consistent look across the platform.CardViewwidgets can have shadows and rounded corners.To create a card with a shadow, use thecard_view:cardElevationattribute.CardViewuses real elevation and dynamic shadows on Android 5.0 (API level 21) and above and falls back to a programmatic shadow implementation on earlier versions. For more information, seeMaintaining Compatibility.Use these properties to customize the appearance of theCardViewwidget: To set the corner radius in your layouts, use thecard_view:cardCornerRadiusattribute. To set the corner radius in your code, use theCardView.setRadiusmethod. To set the background color of a card, use thecard_view:cardBackgroundColorattribute.The following code example shows you how to include aCardViewwidget in your layout:

For more information, see the API reference forCardView.Add Dependencies

TheRecyclerViewandCardViewwidgets are part of thev7 Support Libraries. To use these widgets in your project, add theseGradle dependenciesto your app's module:dependencies { ... compile 'com.android.support:cardview-v7:21.0.+' compile 'com.android.support:recyclerview-v7:21.0.+'}Building Apps with Location & MapsThese classes teach you how to add user location and mapping information to your app. Make your app more helpful and relevant to users by providing information about where they are and the world around them.Receiving Location UpdatesIf your app can continuously track location, it can deliver more relevant information to the user. For example, if your app helps the user find their way while walking or driving, or if your app tracks the location of assets, it needs to get the location of the device at regular intervals. As well as the geographical location (latitude and longitude), you may want to give the user further information such as the bearing (horizontal direction of travel), altitude, or velocity of the device. This information, and more, is available in theLocationobject that your app can retrieve from thefused location provider.While you can get a device's location withgetLastLocation(), as illustrated in the lesson onGetting the Last Known Location, a more direct approach is to request periodic updates from the fused location provider. In response, the API updates your app periodically with the best available location, based on the currently-available location providers such as WiFi and GPS (Global Positioning System). The accuracy of the location is determined by the providers, the location permissions you've requested, and the options you set in the location request.This lesson shows you how to request regular updates about a device's location using therequestLocationUpdates()method in the fused location provider.Connect to Location Services

Location services for apps are provided through Google Play services and the fused location provider. In order to use these services, you connect your app using the Google API Client and then request location updates. For details on connecting with theGoogleApiClient, follow the instructions inGetting the Last Known Location, including requesting the current location.The last known location of the device provides a handy base from which to start, ensuring that the app has a known location before starting the periodic location updates. The lesson onGetting the Last Known Locationshows you how to get the last known location by callinggetLastLocation(). The snippets in the following sections assume that your app has already retrieved the last known location and stored it as aLocationobject in the global variablemCurrentLocation.Apps that use location services must request location permissions. In this lesson you require fine location detection, so that your app can get as precise a location as possible from the available location providers. Request this permission with theuses-permissionelement in your app manifest, as shown in the following example:

Set Up a Location Request

To store parameters for requests to the fused location provider, create aLocationRequest. The parameters determine the levels of accuracy requested. For details of all the options available in the location request, see theLocationRequestclass reference. This lesson sets the update interval, fastest update interval, and priority, as described below:Update intervalsetInterval()- This method sets the rate in milliseconds at which your app prefers to receive location updates. Note that the location updates may be faster than this rate if another app is receiving updates at a faster rate, or slower than this rate, or there may be no updates at all (if the device has no connectivity, for example).Fastest update intervalsetFastestInterval()- This method sets thefastestrate in milliseconds at which your app can handle location updates. You need to set this rate because other apps also affect the rate at which updates are sent. The Google Play services location APIs send out updates at the fastest rate that any app has requested withsetInterval(). If this rate is faster than your app can handle, you may encounter problems with UI flicker or data overflow. To prevent this, callsetFastestInterval()to set an upper limit to the update rate.PrioritysetPriority()- This method sets the priority of the request, which gives the Google Play services location services a strong hint about which location sources to use. The following values are supported: PRIORITY_BALANCED_POWER_ACCURACY- Use this setting to request location precision to within a city block, which is an accuracy of approximately 100 meters. This is considered a coarse level of accuracy, and is likely to consume less power. With this setting, the location services are likely to use WiFi and cell tower positioning. Note, however, that the choice of location provider depends on many other factors, such as which sources are available. PRIORITY_HIGH_ACCURACY- Use this setting to request the most precise location possible. With this setting, the location services are more likely to use GPS (Global Positioning System) to determine the location. PRIORITY_LOW_POWER- Use this setting to request city-level precision, which is an accuracy of approximately 10 kilometers. This is considered a coarse level of accuracy, and is likely to consume less power. PRIORITY_NO_POWER- Use this setting if you need negligible impact on power consumption, but want to receive location updates when available. With this setting, your app does not trigger any location updates, but receives locations triggered by other apps.