1. Trang chủ
  2. » Tất cả

A0092-Peachpit-Android-UI-Fundamentals-Feb-201-MoreBook.vn

336 17 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Contents

  • Introduction

  • Welcome to Android

  • PART 1 BASIC ANDROID UI

    • CHAPTER 1 GETTING STARTED

      • Hello World

      • Basic Structure of an Android App

      • Android UI Basics

      • Tools

      • Wrapping Up

    • CHAPTER 2 CREATING YOUR FIRST APPLICATION

      • Creating an App

      • Getting Started with Android Views

      • Arranging Views

      • Displaying a List

      • Understanding Activities

      • Preventing ANRs

      • Finishing the TimeTracker App

      • Wrapping Up

    • CHAPTER 3 GOING FURTHER

      • Supporting Multiple Screen Sizes

      • Handling Notifications

      • Handling Events

      • Creating Menus

      • Implementing the Time Tracker

      • Wrapping Up

  • PART 2 THE VIEW FRAMEWORK

    • CHAPTER 4 BASIC VIEWS

      • Creating a Basic Form

      • Displaying Images

      • Creating Maps and Displaying Websites

      • Wrapping Up

    • CHAPTER 5 REUSABLE UI

      • Abstracting Your Layouts

      • Abstracting Styles and Themes

      • Using Fragments

      • Wrapping Up

    • CHAPTER 6 NAVIGATION AND DATA LOADING

      • Introducing the Action Bar

      • Navigating Your App

      • Loading Data into Views

      • Wrapping Up

    • CHAPTER 7 ANDROID WIDGETS

      • Creating a Basic Widget

      • Creating a Collection Widget

      • Wrapping Up

  • PART 3 ADVANCED UI DEVELOPMENT

    • CHAPTER 8 HANDLING GESTURES

      • Listening to Touch Events

      • Responding to Gestures

      • Wrapping Up

    • CHAPTER 9 ANIMATION

      • Creating Drawable Animations

      • Creating View Animations

      • Creating Property Animations

      • Wrapping Up

    • CHAPTER 10 CREATING CUSTOM VIEWS

      • Understanding How Android Draws Views

      • Creating a Custom View

      • Adding Custom Attributes to Your Custom Views

      • Creating Compound Components

      • Wrapping Up

    • CHAPTER 11 CREATING ADVANCED GRAPHICS

      • Using Canvas

      • Using RenderScript

      • Using OpenGL

      • Wrapping Up

    • CHAPTER 12 LOCALIZATION AND ACCESSIBILITY

      • Making Your App Available in Multiple Languages

      • Making Your App Accessible

      • Wrapping Up

  • Index

    • A

    • B

    • C

    • D

    • E

    • F

    • G

    • H

    • I

    • J

    • K

    • L

    • M

    • N

    • O

    • P

    • R

    • S

    • T

    • U

    • V

    • W

    • X

    • Z

Nội dung

Android UI Fundamentals n Jason Ostrander Android UI Fundamentals Develop and DesIgn Jason Ostrander Android UI Fundamentals: Develop and Design Jason Ostrander Peachpit Press 1249 Eighth Street Berkeley, CA 94710 510/524-2178 510/524-2221 (fax) Find us on the Web at www.peachpit.com To report errors, please send a note to errata@peachpit.com Peachpit Press is a division of Pearson Education Copyright © 2012 by Jason Ostrander Editor: Clifford Colby Development editor: Robyn Thomas Production editor: Myrna Vladic Copyeditor: Scout Festa Technical editor: Jason LeBrun Cover design: Aren Howell Straiger Interior design: Mimi Heft Compositor: Danielle Foster Indexer: Valerie Haynes Perry Notice of Rights All rights reserved No part of this book may be reproduced or transmitted in any form by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher For information on getting permission for reprints and excerpts, contact permissions@peachpit.com Notice of Liability The information in this book is distributed on an “As Is” basis without warranty While every precaution has been taken in the preparation of the book, neither the author nor Peachpit shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the instructions contained in this book or by the computer software and hardware products described in it Trademarks Android is a trademark of Google Inc., registered in the United States and other countries Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and Peachpit was aware of a trademark claim, the designations appear as requested by the owner of the trademark All other product names and services identified throughout this book are used in editorial fashion only and for the benefit of such companies with no intention of infringement of the trademark No such use, or the use of any trade name, is intended to convey endorsement or other affiliation with this book ISBN 13: 978-0-321-81458-6 ISBN 10: 0-321-81458-4 987654321 Printed and bound in the United States of America To my lovely wife, Susan, who tirelessly supports me in all of my adventures Acknowledgments I could write an entire book thanking people for their help along the way Instead, I’ll have to settle for this short paragraph: Thanks to Chris H for pushing me to consider writing a book and giving me endless encouragement and support To Cliff C for giving me the chance to write this book To Robyn T for keeping me on schedule despite my best efforts To JBL for fixing my code and rocking a mean bass guitar To Scout F and Myrna V for working tirelessly when I was late getting chapters to them To Lucas D and Rob S for reading early chapters and giving me valuable feedback To the entire team at doubleTwist for their dedication to making great Android software To the Android team at Google for creating a great platform To my family for their continuing support despite my dropping off the face of the earth To Peachpit for giving me the opportunity to write this for you And to you, the reader, for giving me the chance to teach you in whatever small way I can Bio Jason Ostrander is a web and mobile software developer working at Silicon Valley startup doubleTwist, where he makes syncing media to Android phones simple Prior to that, he solved networking problems at energy management startup Sentilla and defense company Northrop Grumman Jason holds an MS in electrical engineering from UCLA He lives with his wife in San Francisco’s Mission District, where he spends his time searching for the perfect chile relleno Iv Android Ui FUndAmentAls: develop And design contents Introduction viii Welcome to Android x Part BAsIc ANDROID UI Chapter GeTTING sTARTeD Hello World Basic Structure of an Android App Android UI Basics 14 Tools 22 Wrapping Up 32 Chapter cReATING YOUR FIRsT APPLIcATION 34 Creating an App 36 Getting Started with Android Views 37 Arranging Views 41 Displaying a List 52 Understanding Activities 57 Preventing ANRs 64 Finishing the TimeTracker App 71 Wrapping Up 73 Chapter GOING FURTheR 74 Supporting Multiple Screen Sizes 76 Handling Notifications 84 Handling Events 92 Creating Menus 96 Implementing the Time Tracker 102 Wrapping Up 107 Contents v Part The vIew FRAmewORk Chapter BAsIc vIews 110 Creating a Basic Form 112 Displaying Images 124 Creating Maps and Displaying Websites 130 Wrapping Up 136 Chapter ReUsABLe UI 138 Abstracting Your Layouts 140 Abstracting Styles and Themes 148 Using Fragments 153 Wrapping Up 162 Chapter NAvIGATION AND DATA LOADING 164 Introducing the Action Bar 166 Navigating Your App 172 Loading Data into Views 181 Wrapping Up 186 Chapter ANDROID wIDGeTs 188 Creating a Basic Widget 190 Creating a Collection Widget 206 Wrapping Up 211 vI Android Ui FUndAmentAls: develop And design Part ADvANceD UI DeveLOPmeNT Chapter hANDLING GesTURes 214 Listening to Touch Events 216 Responding to Gestures 224 Wrapping Up 229 Chapter ANImATION 230 Creating Drawable Animations 232 Creating View Animations 235 Creating Property Animations 246 Wrapping Up 255 Chapter 10 cReATING cUsTOm vIews 256 Understanding How Android Draws Views 258 Creating a Custom View 259 Adding Custom Attributes to Your Custom Views 267 Creating Compound Components 274 Wrapping Up 279 Chapter 11 cReATING ADvANceD GRAPhIcs 280 Using Canvas 282 Using RenderScript 289 Using OpenGL 294 Wrapping Up 301 Chapter 12 LOcALIzATION AND AccessIBILITY 302 Making Your App Available in Multiple Languages 304 Making Your App Accessible 309 Wrapping Up 315 Index 316 ii introduction There is a revolution happening in the technology industry Touchscreen interfaces, combined with low-cost and ubiquitous smartphones, have created a perfect storm for disruptive innovation Android is at the forefront of this change, bringing a free and open-source platform on which developers can create the next generation of applications With free development tools and an open market, anyone can develop applications that reach a worldwide market But why choose to develop for Android? Android now runs on the majority of smartphones in the United States And it’s quickly expanding into new markets and device types The last year has seen the introduction of hundreds of Android-based tablets, including the hit Kindle Fire Google has ported Android to TVs with its Google TV platform, and many manufacturers are beginning to ship TVs with Android built in Boeing has selected Android as the entertainment platform for its new Dreamliner jet Ford is integrating Android into its in-dash SYNC entertainment system And Android is quickly gaining traction in the developing world, especially in Africa, where the need for low-cost handsets is greatest Yet for all of the platform’s promise, the majority of Android applications still lack the visual polish of their iOS counterparts This book aims to address that issue by providing developers with a solid foundation for building app UIs It will cover the basics of UI development on Android, teach best practices for creating flexible layouts, and give you tips on how to optimize your UI for smooth, fluid performance I created this book in the hope that it will help developers to create beautiful applications Who am I? I’ve been developing software professionally for almost ten years, and I’ve focused on embedded and mobile software for the last five In my day job, I work for one of the top Android development companies and write code that millions of people use every day Android development can be difficult at times, and the challenges of supporting such a diversity of devices can be daunting But with a good idea, a solid understanding of the framework, and a little persistence, anyone can create a great app that is used by millions of people I hope you’ll enjoy reading this book as much as I enjoyed writing it for you vIII Android Ui FUndAmentAls: develop And design Who this Book is For This book is aimed at beginning Android developers who are interested in creating great user interfaces You are expected to know basic Java programming and XML syntax The focus of this book is on UI While you don’t need to have experience writing Android software, many basic Android concepts are only described in passing It will help you to have a rudimentary knowledge of Android development Who this Book is Not For This book is not a general introduction to programming for Android While it is intended for beginning Android developers, the focus is on user interface tools and programming In particular, this book will not cover basic Android concepts such as intents, services, or content providers Further, this book will not be an introduction to the Java programming language or to XML You should know how to program and how to read XML hoW You Will learN Throughout this book, you’ll learn by creating an actual app, a simple time tracker Each chapter includes detailed examples of real Android code that you will compile and run All code for the book can be found at the book’s website: www.peachpit.com/androiduifundamentals What You Will learN You’ll learn how to create user interfaces for Android applications From the most basic concepts, like activities and views, all the way to advanced graphics using RenderScript, this book covers everything you will use to build the user interface of your apps a Note aBout aNdroid VersioNs This book was written to Android version APIs and best practices, but it is compatible back to Android version 2.2 When relevant, notes and tips are included to indicate when an API is deprecated or no longer appropriate The Android compatibility library, a package of classes that back-port several newer features, will be used throughout the book introdUCtion Ix

Ngày đăng: 12/12/2020, 16:24

w