Android Tips Round-Up, Part 4

Here's the fourth round-up of Android tips I've been posting.

More: Part 1 | Part 2 | Part 3 | Part 4 | Part 5

Activity.isChangingConfigurations() - Often times you don't need to do quite as much saving of state if all that's happening is the configuration is changing.

SearchRecentSuggestionsProvider - A quick and easy way to create a recents suggestion provider.

ViewTreeObserver - This is an amazing utility; it can be grabbed from any View and used to monitor the state of the View hierarchy. My most often use for it is to determine when Views have been measured (usually for animation purposes).

org.gradle.daemon=true - Helps reduce the startup time of of Gradle builds. Only really applies to command-line builds as Android Studio already tries to use the daemon.

DatabaseUtils - A variety of useful tools for database operations.

android:weightSum (LinearLayout) - Want to use layout weights, but don't want them to fill the entire LinearLayout? That's what weightSum can do by defining the total weight.

android:duplicateParentState (View) - Makes the child duplicate the state of the parent - for example, if you've got a ViewGroup that is clickable, then you can use this to make its children change state when it is clicked.

android:clipChildren (ViewGroup) - If disabled, this lets the children of a ViewGroup draw outside their parent's bounds. Great for animations.

android:fillViewport (ScrollView) - Best explained in this post, this helps solve a problem with ScrollViews that may not always have enough content to actually fill the height of the screen.

android:tileMode (BitmapDrawable) - Lets you create repeated patterns with images.

android:enterFadeDuration/android:exitFadeDuration (Drawables) - For Drawables that have multiple states, this lets you define a fade before/after the drawable shows.

android:scaleType (ImageView) - Defines how to scale/crop a drawable within an ImageView. "centerCrop" and "centerInside" are regular settings for me.

<merge> - Lets you include a layout in another without creating a duplicate ViewGroup (more info). Also good for custom ViewGroups; you can inflate a layout with <merge> inside the constructor to define its children automatically.

AtomicFile - Manipulates a file atomically by using a backup file. I've written this myself before, it's good to have an official (and better-written) version of it.

comments powered by Disqus