Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android View Stuff. TextViews Display text Display images???

Similar presentations


Presentation on theme: "Android View Stuff. TextViews Display text Display images???"— Presentation transcript:

1 Android View Stuff

2 TextViews Display text Display images???

3 TextView Drawables TextViews allow drawables to appear to the left of, above, to the right of, and below the text.

4 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_launcher" android:text="Drawable Left" android:layout_margin="10dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="@drawable/ic_launcher" android:text="Drawable Top" android:layout_margin="10dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableRight="@drawable/ic_launcher" android:text="Drawable Right" android:layout_margin="10dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableBottom="@drawable/ic_launcher" android:text="Drawable Bottom" android:layout_margin="10dp"/>

5 setError() Method available to TextView and EditText to display an error message to the user. This is very useful for user input validation.

6 ImageView Use this View when you want to display an image in your application. Many beginners will misuse the ImageView by using the incorrect property.

7 ImageView src property Use the android:src property to set a drawable as the content of the ImageView. Don’t use android:background unless you want the image to have a background img.

8 ImageView Example <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher"/>

9 ImageView Example with a background <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:background="#FFFF0000"/>

10 ImageView scaleType Control how your image is scaled and positioned inside the ImageView – Useful when your image is too big – Useful when your image is too small

11 ImageView scaleType : center Scale TypeDescription centerDisplays the image centered in the view with no scaling. centerCropScales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view. centerInsideScales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center. fitCenterScales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view. fitStartSame as fitCenter but aligned to the top left of the view. fitEndSame as fitCenter but aligned to the bottom right of the view. fitXYScales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio. matrixScales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

12 ImageView scaleType : centerCrop Scale TypeDescription centerDisplays the image centered in the view with no scaling. centerCropScales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view. centerInsideScales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center. fitCenterScales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view. fitStartSame as fitCenter but aligned to the top left of the view. fitEndSame as fitCenter but aligned to the bottom right of the view. fitXYScales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio. matrixScales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

13 ImageView scaleType : centerInside Scale TypeDescription centerDisplays the image centered in the view with no scaling. centerCropScales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view. centerInsideScales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center. fitCenterScales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view. fitStartSame as fitCenter but aligned to the top left of the view. fitEndSame as fitCenter but aligned to the bottom right of the view. fitXYScales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio. matrixScales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

14 ImageView scaleType : fitCenter Scale TypeDescription centerDisplays the image centered in the view with no scaling. centerCropScales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view. centerInsideScales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center. fitCenterScales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view. fitStartSame as fitCenter but aligned to the top left of the view. fitEndSame as fitCenter but aligned to the bottom right of the view. fitXYScales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio. matrixScales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

15 ImageView scaleType : fitStart Scale TypeDescription centerDisplays the image centered in the view with no scaling. centerCropScales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view. centerInsideScales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center. fitCenterScales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view. fitStartSame as fitCenter but aligned to the top left of the view. fitEndSame as fitCenter but aligned to the bottom right of the view. fitXYScales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio. matrixScales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

16 ImageView scaleType : fitEnd Scale TypeDescription centerDisplays the image centered in the view with no scaling. centerCropScales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view. centerInsideScales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center. fitCenterScales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view. fitStartSame as fitCenter but aligned to the top left of the view. fitEndSame as fitCenter but aligned to the bottom right of the view. fitXYScales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio. matrixScales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

17 ImageView scaleType : fitXY Scale TypeDescription centerDisplays the image centered in the view with no scaling. centerCropScales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view. centerInsideScales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center. fitCenterScales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view. fitStartSame as fitCenter but aligned to the top left of the view. fitEndSame as fitCenter but aligned to the bottom right of the view. fitXYScales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio. matrixScales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

18 ImageView scaleType : matrix Scale TypeDescription centerDisplays the image centered in the view with no scaling. centerCropScales the image such that both the x and y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; crops any part of the image that exceeds the size of the view; centers the image in the view. centerInsideScales the image to fit inside the view, while maintaining the image aspect ratio. If the image is already smaller than the view, then this is the same as center. fitCenterScales the image to fit inside the view, while maintaining the image aspect ratio. At least one axis will exactly match the view, and the result is centered inside the view. fitStartSame as fitCenter but aligned to the top left of the view. fitEndSame as fitCenter but aligned to the bottom right of the view. fitXYScales the x and y dimensions to exactly match the view size; does not maintain the image aspect ratio. matrixScales the image using a supplied Matrix class. The matrix can be supplied using the setImageMatrix method. A Matrix class can be used to apply transformations such as rotations to an image.

19 ImageView ScaleType Info http://www.peachpit.com/articles/article.aspx ?p=1846580&seqNum=2 http://www.peachpit.com/articles/article.aspx ?p=1846580&seqNum=2

20 Android:tint ImageView’s have an attribute that allows the source image of the view to be tinted by a color.

21 ImageButton We’re familiar with a Button – Default background provided by the platform – Displays Text Well Android supports an ImageButton – Looks like a regular button – Default background provided by the platform – Displays an Image

22 Why Buttons are awesome Android provides a method for giving a button a state list that defines which images should be shown while the button is: – Normal – Focused – Enabled – Disabled – Pressed

23 Hiding the default background on an ImageButton If you want to use an ImageButton but don’t want to see the default background, you can hide it. – Set the android:background=“#00000000” – Set the android:background=“@android:color/transparent

24 ShapeDrawables An XML file that defines a geometric shape, including colors and gradients. Creates a ShapeDrawable.ShapeDrawable

25 shapecornersgradientpaddingsizesolidstroke

26 ShapeDrawable Examples

27

28 What is a 9-Patch An Image that has the capability to specify stretchable regions.

29 Use Case for 9-Patch

30 More Info on 9-Patch Android 9 Patch Tool A Simple guide to 9-patch for Android UI


Download ppt "Android View Stuff. TextViews Display text Display images???"

Similar presentations


Ads by Google