Android ImageView Picture Adaptive

Source: Internet
Author: User

Images downloaded on the network adaptive: android:adjustviewbounds= "true" (which is explained in detail below)
<imageview android:id= "@+id/dynamic_item_image" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_gravity= "Top" android:layout_margintop= "5dip" android:adjustviewbounds= "true" android:background= "@drawable/imageview_background"/>
In addition, android:background= "@drawable/imageview_background" is a frame that adds a border to the picture, where

Imageview_background.xml:

<?xmlversion= "1.0" encoding= "Utf-8"? ><shape   Xmlns:android= "http://schemas.android.com/apk/res/android" ><solid android:color= "@color/white"/>< Stroke android:width= "2.0dip" android:color= "#99D9D9D9"/> <cornersandroid:radius= "2.0dip"/> < paddingandroid:left= "5.0dip" android:top= "5.0dip" android:right= "5.0dip" android:bottom= "5.0dip"/></shape >

ImageView Property Description:

1. Class overview

Displays any image, as an example. The ImageView class can load pictures from a variety of sources, such as a resource or a picture library, and needs to calculate the size of the image, which can be used in other layouts, and provides various display options such as zooming and shading (rendering).

2. Xml attributes

Property name

Describe

Android:adjustviewbounds

Whether to maintain the aspect ratio. Need to be used with maxwidth, maxheight, otherwise no effect is used alone.

Android:croptopadding

Whether to intercept the specified area with white space instead. Individually set no effect, need to work with scrolly, the effect is as follows, implementation code see Code section:

Android:maxheight

Sets the maximum height of the view, which is not valid for use alone and needs to be used with setadjustviewbounds. If you want to set the image to a fixed size and want to maintain the picture aspect ratio, you need the following settings:

1) Set Setadjustviewbounds to true;

2) Set MaxWidth, MaxHeight;

3) Set settings Layout_width and Layout_height to Wrap_content.

Android:maxwidth

Sets the maximum width of the view. Ditto.

Android:scaletype

Sets how the picture is filled.

Matrix

0

Use a matrix to draw

Fitxy

1

Stretch the picture (not proportionally) to fill the view's width height

Layout_

Height

: 30px


Layout_

Width

: 120px

Fitstart

2

Stretch the picture proportionally, the height of the picture is the height of the view, and it appears on the left side of the view

Fitcenter

3

Stretches the picture proportionally to the height of the view and appears in the middle of the view

Fitend

4

Stretch the picture proportionally, the height of the picture is the height of the view, and appears on the right side of the view

Center

5

Displays the picture at the original size, but the picture is wider than the width of the view, and the middle part of the picture shows

Layout_

Height

: 60px


Layout_

Width

: 80px


Padding

: 10px

Centercrop

6

Enlarges the original image proportionally to the width and height of a side view.

Centerinside

7

When the original image is wide or equal to the width of the view, it is centered on the original size, whereas the original is scaled to the view's wide-height center display.

Android:src

Set the view's drawable (slice, or color, but need to specify the size of the view)

Android:tint

Renders the picture as a specified color. See:

The left is the original, the right side is the set effect, see the following code.

Android ImageView Picture Adaptive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.