Git Product home page Git Product logo

android-imageviewplus's Introduction

ImageViewPlus

ImageViewPlus is an extension of ImageView to enhance its functionality.

  • Top-aligned scale mode to enable a top-aligned image inside of an ImageViewPlus (top_crop)
  • Layer drawable defines the wrapper drawable to use for content. This is useful for adding a selector for states on the ImageView when the states have overlay on the content drawable
  • Default drawable (for when no drawable is set)

Usage

To use ImageViewPlus in your layout: 0. Add the ImageViewPlus project as a library reference to your project 0. Define your layer drawable (res/drawable/image_selector.xml in this example)

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item android:id="@+id/content_drawable">
            <shape android:shape="rectangle" />
        </item>
        <item>
            <selector>
                <item android:state_pressed="true">
                    <shape android:shape="rectangle" >
                        <solid android:color="#3000" />
                    </shape>
                </item>
                <item>
                    <shape android:shape="rectangle" >
                        <solid android:color="#0fff" />
                    </shape>
                </item>
            </selector>
        </item>
    </layer-list>

 This particular drawable shows a semi-transparent black overlay on the content when pressed
  1. Define your layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res/com.example.app"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        
            <com.meetme.android.imageviewplus.ImageViewPlus
                android:id="@+id/top_crop_image"
                android:layout_width="match_parent"
                android:layout_height="210dp"
                android:src="@drawable/example_image"
                app:scaleType="fitCenter"
                app:layerDrawable="@drawable/image_selector"
                app:contentLayerId="@id/content_drawable" />
        
    </LinearLayout>
    

    Important: The xmlns:app="http://schemas.android.com/apk/res/com.example.app" line needs to use the namespace of your application for the com.example.app portion to function properly.

Notes

  • ImageViewPlus#getDrawable() will return the drawable of the content, not the layer drawable (if used). This is done to protect existing usage that assume setImage* methods and getDrawable() use the same underlying field (such as Google's ImageFetcher example).
  • With the aforementioned ImageFetcher example, the default drawable implementation may not function as expected. ImageFetcher sets a Drawable (AsyncDrawable) on the attached ImageView instance which we do not introspect or deal with in any way.
  • The default drawable is set to the content when the content drawable is not set (using one of the setImage* methods).

Contributors

License

ImageViewPlus is provided under the Apache 2.0 license:

Copyright 2013 MeetMe, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributing

To make contributions, fork this repository, commit your changes, and submit a pull request.

android-imageviewplus's People

Contributors

dallasgutauckis avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.