Discrollview

Regularly, I am pleasantly surprised by websites using a pattern I called the discrollver pattern. I'm sure you already know what I'm talking about but if not, http://vimeo.com/player is a good example. When you scroll, widgets appear from nowhere by fade, translation or scale.

With DiscrollView, I wanted to import this pattern on Android. This is an 0.0.1 alpha version because you have to do all the transformation work (fade, translation, scale etc) yourself base on a ratio value. I'm going to add some transformation presets (translation from left to right + fade in for example) to make the library more ready to use for lazy developers.

Animated gif (on youtube)

Try out the sample APK here

Or browse the source code of the sample application for a complete example of use.

Including in your project

Just add the library to your application as a library project.

Usage

Using the library is simple, just look at the source code of the provided sample here

build.gradle

compile 'com.github.flavienlaurent.discrollview:library:0.0.2@aar'

The main layout

You must use the DiscrollViewContent view.

<com.flavienlaurent.discrollview.lib.DiscrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:discrollve="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.flavienlaurent.discrollview.lib.DiscrollViewContent
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- here you put discrollvable views -->

    </com.flavienlaurent.discrollview.lib.DiscrollViewContent>

</com.flavienlaurent.discrollview.lib.DiscrollView>

Discrollvable views

You can apply some transformation on discroll:

  • alpha
  • scale
  • translation (fromLeft, fromBottom, fromRight, fromTop) fromLeft+fromRight and fromBottom+fromTop are forbidden couples.
  • bgcolor
discrollve:discrollve_alpha="true"
discrollve:discrollve_translation="fromLeft|fromBottom"
discrollve:discrollve_scaleX="true"
discrollve:discrollve_scaleY="true"
discrollve:discrollve_fromBgColor="#88EE66"
discrollve:discrollve_toBgColor="#000000"
discrollve:discrollve_threshold="0.3"

The threshold attribute is used to trigger the discrollve at a specified ratio. For example, if threshold=0.3, the discrollve starts when the ratio >= 0.3.

A simple example

<com.flavienlaurent.discrollview.lib.DiscrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:discrollve="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.flavienlaurent.discrollview.lib.DiscrollViewContent
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="600dp"
            android:background="@android:color/white"
            android:textColor="@android:color/black"
            android:padding="25dp"
            android:textSize="72sp"
            android:gravity="center"
            android:fontFamily="serif"
            android:text="Do you love cheese?" />

        <View
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="#007788"
            discrollve:discrollve_alpha="true"
            discrollve:discrollve_threshold="0.3" />

        <ImageView
            android:layout_width="200dp"
            android:layout_height="120dp"
            discrollve:discrollve_alpha="true"
            discrollve:discrollve_translation="fromLeft|fromBottom"
            android:src="@drawable/cheese1" />

        <View
            android:layout_width="match_parent"
            android:layout_height="200dp"
            discrollve:discrollve_fromColor="#88EE66"
            discrollve:discrollve_toColor="#000000" />

        <ImageView
            android:layout_width="220dp"
            android:layout_height="110dp"
            android:layout_gravity="right"
            android:src="@drawable/cheese2"
            discrollve:discrollve_translation="fromRight" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="20dp"
            android:fontFamily="serif"
            android:gravity="center"
            android:text="When the cheese comes out everybody's happy pecorino red leicester"
            android:textSize="18sp"
            discrollve:discrollve_alpha="true"
            discrollve:discrollve_translation="fromBottom" />

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:layout_gravity="center"
            android:src="@drawable/ilovecheese_heart"
            discrollve:discrollve_scaleX="true"
            discrollve:discrollve_scaleY="true"  />

    </com.flavienlaurent.discrollview.lib.DiscrollViewContent>
</com.flavienlaurent.discrollview.lib.DiscrollView>

License

Copyright 2013 Flavien Laurent

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.


블로그 이미지

날기억해

Android / IOS / PHP / System Engineer / Service Architecture/ MongoDB / AWS / Mysql / Linux / Python / C++ / Vue.js / node.js / Java / Iot / BLE / Firebase / Bigdata Architecture / AD Server / SDK / Epub /

,

BlurEffect

IT/Android 2014. 3. 25. 13:17


BlurEffectForAndroidDesign

Sample to show how to implement blur graphical tricks

All the explanations could be found here: http://nicolaspomepuy.fr/?p=18

A sample is available on the Google Play Store at this adress: https://play.google.com/store/apps/details?id=com.npi.blureffect

Screenshots :

Alt text

Alt text

Alt text

'IT > Android' 카테고리의 다른 글

ActionBar Hide Icon  (0) 2014.04.02
안드로이드 디컴파일, 리컴파일  (0) 2014.03.31
android residemenu  (0) 2014.03.25
android blindsview  (0) 2014.03.25
HeaderGridView  (0) 2014.03.25
블로그 이미지

날기억해

Android / IOS / PHP / System Engineer / Service Architecture/ MongoDB / AWS / Mysql / Linux / Python / C++ / Vue.js / node.js / Java / Iot / BLE / Firebase / Bigdata Architecture / AD Server / SDK / Epub /

,

android residemenu

IT/Android 2014. 3. 25. 13:14

AndroidResideMenu


中文说明请点击 这里

The idea of ResideMenu is from Dribble 1 and 2. It has come true and run in iOS devices. iOS ResideMenu This project is the RefsideMenu Android version. The visual effect is partly referred to iOS version of ResideMenu. And thanks to the authors for the above idea and contribution. 

DEMO

This copy is the demo.

Requirements

Run in Android 2.3 +

Installation

  1. import ResideMenu project to your workspace.
  2. make it as a dependency library project to your main project. 
    ( see example )

or

If you want to merge ResideMenu with your project, you should follow these steps.

  1. Copy all files from src/com/special/ResideMenu to your project.
  2. Copy libs/nineoldandroids-library-2.4.0.jar to your project’s corresponding path: libs/
  3. Copy res/drawable-hdpi/shadow.9.png to your project’s corresponding path: res/drawable-hdpi/
  4. Copy res/layout/residemenu.xml and residemenu_item.xml to your project’s corresponding path: res/layout

Usage

init ResideMenu: write these code in Activity onCreate()

        // attach to current activity;
        resideMenu = new ResideMenu(this);
        resideMenu.setBackground(R.drawable.menu_background);
        resideMenu.attachToActivity(this);

        // create menu items;
        String titles[] = { "Home", "Profile", "Calendar", "Settings" };
        int icon[] = { R.drawable.icon_home, R.drawable.icon_profile, R.drawable.icon_calendar, R.drawable.icon_settings };

        for (int i = 0; i < titles.length; i++){
            ResideMenuItem item = new ResideMenuItem(this, icon[i], titles[i]);
            item.setOnClickListener(this);
            resideMenu.addMenuItem(item);
        }

If you want to use slipping gesture to operate(lock/unlock) the menu, override this code in Acitivity dispatchTouchEvent() (please duplicate the followed code in dispatchTouchEvent() of Activity.

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        return resideMenu.onInterceptTouchEvent(ev) || super.dispatchTouchEvent(ev);
    }

On some occasions, the slipping gesture function for locking/unlocking menu, may have conflicts with your widgets, such as viewpager. By then you can add the viewpager to ignored view, please refer to next chapter – Ignored Views.

open/close menu

resideMenu.openMenu();
resideMenu.closeMenu();

listen in the menu state

    resideMenu.setMenuListener(menuListener);
    private ResideMenu.OnMenuListener menuListener = new ResideMenu.OnMenuListener() {
        @Override
        public void openMenu() {
            Toast.makeText(mContext, "Menu is opened!", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void closeMenu() {
            Toast.makeText(mContext, "Menu is closed!", Toast.LENGTH_SHORT).show();
        }
    };

Ignored Views

On some occasions, the slipping gesture function for locking/unlocking menu, may have conflicts with your widgets such as viewpager.By then you can add the viewpager to ignored view.

        // add gesture operation's ignored views
        FrameLayout ignored_view = (FrameLayout) findViewById(R.id.ignored_view);
        resideMenu.addIgnoredView(ignored_view);

So that in ignored view’s workplace, the slipping gesture will not be allowed to operate menu.

About me

A student from SCAU China.
Email: specialcyci#gmail.com


https://github.com/SpecialCyCi/AndroidResideMenu

'IT > Android' 카테고리의 다른 글

안드로이드 디컴파일, 리컴파일  (0) 2014.03.31
BlurEffect  (0) 2014.03.25
android blindsview  (0) 2014.03.25
HeaderGridView  (0) 2014.03.25
Drag And Drop GridView use Adapter  (0) 2014.03.25
블로그 이미지

날기억해

Android / IOS / PHP / System Engineer / Service Architecture/ MongoDB / AWS / Mysql / Linux / Python / C++ / Vue.js / node.js / Java / Iot / BLE / Firebase / Bigdata Architecture / AD Server / SDK / Epub /

,

HeaderGridView

IT/Android 2014. 3. 25. 13:04
Android 4.3 의 갤러리 어플리케이션에 존재하는 소스이다.
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * 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.
 */

package com.android.photos.views;

import android.content.Context;
import android.database.DataSetObservable;
import android.database.DataSetObserver;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.WrapperListAdapter;

import java.util.ArrayList;

/**
 * A {@link GridView} that supports adding header rows in a
 * very similar way to {@link ListView}.
 * See {@link HeaderGridView#addHeaderView(View, Object, boolean)}
 */
public class HeaderGridView extends GridView {
    private static final String TAG = "HeaderGridView";

    /**
     * A class that represents a fixed view in a list, for example a header at the top
     * or a footer at the bottom.
     */
    private static class FixedViewInfo {
        /** The view to add to the grid */
        public View view;
        public ViewGroup viewContainer;
        /** The data backing the view. This is returned from {@link ListAdapter#getItem(int)}. */
        public Object data;
        /** true if the fixed view should be selectable in the grid */
        public boolean isSelectable;
    }

    private ArrayList mHeaderViewInfos = new ArrayList();

    private void initHeaderGridView() {
        super.setClipChildren(false);
    }

    public HeaderGridView(Context context) {
        super(context);
        initHeaderGridView();
    }

    public HeaderGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initHeaderGridView();
    }

    public HeaderGridView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initHeaderGridView();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        ListAdapter adapter = getAdapter();
        if (adapter != null && adapter instanceof HeaderViewGridAdapter) {
            ((HeaderViewGridAdapter) adapter).setNumColumns(getNumColumns());
        }
    }

    @Override
    public void setClipChildren(boolean clipChildren) {
       // Ignore, since the header rows depend on not being clipped
    }

    /**
     * Add a fixed view to appear at the top of the grid. If addHeaderView is
     * called more than once, the views will appear in the order they were
     * added. Views added using this call can take focus if they want.
     * 

* NOTE: Call this before calling setAdapter. This is so HeaderGridView can wrap * the supplied cursor with one that will also account for header views. * * @param v The view to add. * @param data Data to associate with this view * @param isSelectable whether the item is selectable */ public void addHeaderView(View v, Object data, boolean isSelectable) { ListAdapter adapter = getAdapter(); if (adapter != null && ! (adapter instanceof HeaderViewGridAdapter)) { throw new IllegalStateException( "Cannot add header view to grid -- setAdapter has already been called."); } FixedViewInfo info = new FixedViewInfo(); FrameLayout fl = new FullWidthFixedViewLayout(getContext()); fl.addView(v); info.view = v; info.viewContainer = fl; info.data = data; info.isSelectable = isSelectable; mHeaderViewInfos.add(info); // in the case of re-adding a header view, or adding one later on, // we need to notify the observer if (adapter != null) { ((HeaderViewGridAdapter) adapter).notifyDataSetChanged(); } } /** * Add a fixed view to appear at the top of the grid. If addHeaderView is * called more than once, the views will appear in the order they were * added. Views added using this call can take focus if they want. *

* NOTE: Call this before calling setAdapter. This is so HeaderGridView can wrap * the supplied cursor with one that will also account for header views. * * @param v The view to add. */ public void addHeaderView(View v) { addHeaderView(v, null, true); } public int getHeaderViewCount() { return mHeaderViewInfos.size(); } /** * Removes a previously-added header view. * * @param v The view to remove * @return true if the view was removed, false if the view was not a header * view */ public boolean removeHeaderView(View v) { if (mHeaderViewInfos.size() > 0) { boolean result = false; ListAdapter adapter = getAdapter(); if (adapter != null && ((HeaderViewGridAdapter) adapter).removeHeader(v)) { result = true; } removeFixedViewInfo(v, mHeaderViewInfos); return result; } return false; } private void removeFixedViewInfo(View v, ArrayList where) { int len = where.size(); for (int i = 0; i < len; ++i) { FixedViewInfo info = where.get(i); if (info.view == v) { where.remove(i); break; } } } @Override public void setAdapter(ListAdapter adapter) { if (mHeaderViewInfos.size() > 0) { HeaderViewGridAdapter hadapter = new HeaderViewGridAdapter(mHeaderViewInfos, adapter); int numColumns = getNumColumns(); if (numColumns > 1) { hadapter.setNumColumns(numColumns); } super.setAdapter(hadapter); } else { super.setAdapter(adapter); } } private class FullWidthFixedViewLayout extends FrameLayout { public FullWidthFixedViewLayout(Context context) { super(context); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int targetWidth = HeaderGridView.this.getMeasuredWidth() - HeaderGridView.this.getPaddingLeft() - HeaderGridView.this.getPaddingRight(); widthMeasureSpec = MeasureSpec.makeMeasureSpec(targetWidth, MeasureSpec.getMode(widthMeasureSpec)); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } /** * ListAdapter used when a HeaderGridView has header views. This ListAdapter * wraps another one and also keeps track of the header views and their * associated data objects. *

This is intended as a base class; you will probably not need to * use this class directly in your own code. */ private static class HeaderViewGridAdapter implements WrapperListAdapter, Filterable { // This is used to notify the container of updates relating to number of columns // or headers changing, which changes the number of placeholders needed private final DataSetObservable mDataSetObservable = new DataSetObservable(); private final ListAdapter mAdapter; private int mNumColumns = 1; // This ArrayList is assumed to NOT be null. ArrayList mHeaderViewInfos; boolean mAreAllFixedViewsSelectable; private final boolean mIsFilterable; public HeaderViewGridAdapter(ArrayList headerViewInfos, ListAdapter adapter) { mAdapter = adapter; mIsFilterable = adapter instanceof Filterable; if (headerViewInfos == null) { throw new IllegalArgumentException("headerViewInfos cannot be null"); } mHeaderViewInfos = headerViewInfos; mAreAllFixedViewsSelectable = areAllListInfosSelectable(mHeaderViewInfos); } public int getHeadersCount() { return mHeaderViewInfos.size(); } @Override public boolean isEmpty() { return (mAdapter == null || mAdapter.isEmpty()) && getHeadersCount() == 0; } public void setNumColumns(int numColumns) { if (numColumns < 1) { throw new IllegalArgumentException("Number of columns must be 1 or more"); } if (mNumColumns != numColumns) { mNumColumns = numColumns; notifyDataSetChanged(); } } private boolean areAllListInfosSelectable(ArrayList infos) { if (infos != null) { for (FixedViewInfo info : infos) { if (!info.isSelectable) { return false; } } } return true; } public boolean removeHeader(View v) { for (int i = 0; i < mHeaderViewInfos.size(); i++) { FixedViewInfo info = mHeaderViewInfos.get(i); if (info.view == v) { mHeaderViewInfos.remove(i); mAreAllFixedViewsSelectable = areAllListInfosSelectable(mHeaderViewInfos); mDataSetObservable.notifyChanged(); return true; } } return false; } @Override public int getCount() { if (mAdapter != null) { return getHeadersCount() * mNumColumns + mAdapter.getCount(); } else { return getHeadersCount() * mNumColumns; } } @Override public boolean areAllItemsEnabled() { if (mAdapter != null) { return mAreAllFixedViewsSelectable && mAdapter.areAllItemsEnabled(); } else { return true; } } @Override public boolean isEnabled(int position) { // Header (negative positions will throw an ArrayIndexOutOfBoundsException) int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns; if (position < numHeadersAndPlaceholders) { return (position % mNumColumns == 0) && mHeaderViewInfos.get(position / mNumColumns).isSelectable; } // Adapter final int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = 0; if (mAdapter != null) { adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.isEnabled(adjPosition); } } throw new ArrayIndexOutOfBoundsException(position); } @Override public Object getItem(int position) { // Header (negative positions will throw an ArrayIndexOutOfBoundsException) int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns; if (position < numHeadersAndPlaceholders) { if (position % mNumColumns == 0) { return mHeaderViewInfos.get(position / mNumColumns).data; } return null; } // Adapter final int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = 0; if (mAdapter != null) { adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.getItem(adjPosition); } } throw new ArrayIndexOutOfBoundsException(position); } @Override public long getItemId(int position) { int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns; if (mAdapter != null && position >= numHeadersAndPlaceholders) { int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.getItemId(adjPosition); } } return -1; } @Override public boolean hasStableIds() { if (mAdapter != null) { return mAdapter.hasStableIds(); } return false; } @Override public View getView(int position, View convertView, ViewGroup parent) { // Header (negative positions will throw an ArrayIndexOutOfBoundsException) int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns ; if (position < numHeadersAndPlaceholders) { View headerViewContainer = mHeaderViewInfos .get(position / mNumColumns).viewContainer; if (position % mNumColumns == 0) { return headerViewContainer; } else { if (convertView == null) { convertView = new View(parent.getContext()); } // We need to do this because GridView uses the height of the last item // in a row to determine the height for the entire row. convertView.setVisibility(View.INVISIBLE); convertView.setMinimumHeight(headerViewContainer.getHeight()); return convertView; } } // Adapter final int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = 0; if (mAdapter != null) { adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.getView(adjPosition, convertView, parent); } } throw new ArrayIndexOutOfBoundsException(position); } @Override public int getItemViewType(int position) { int numHeadersAndPlaceholders = getHeadersCount() * mNumColumns; if (position < numHeadersAndPlaceholders && (position % mNumColumns != 0)) { // Placeholders get the last view type number return mAdapter != null ? mAdapter.getViewTypeCount() : 1; } if (mAdapter != null && position >= numHeadersAndPlaceholders) { int adjPosition = position - numHeadersAndPlaceholders; int adapterCount = mAdapter.getCount(); if (adjPosition < adapterCount) { return mAdapter.getItemViewType(adjPosition); } } return AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER; } @Override public int getViewTypeCount() { if (mAdapter != null) { return mAdapter.getViewTypeCount() + 1; } return 2; } @Override public void registerDataSetObserver(DataSetObserver observer) { mDataSetObservable.registerObserver(observer); if (mAdapter != null) { mAdapter.registerDataSetObserver(observer); } } @Override public void unregisterDataSetObserver(DataSetObserver observer) { mDataSetObservable.unregisterObserver(observer); if (mAdapter != null) { mAdapter.unregisterDataSetObserver(observer); } } @Override public Filter getFilter() { if (mIsFilterable) { return ((Filterable) mAdapter).getFilter(); } return null; } @Override public ListAdapter getWrappedAdapter() { return mAdapter; } public void notifyDataSetChanged() { mDataSetObservable.notifyChanged(); } } }

'IT > Android' 카테고리의 다른 글

android residemenu  (0) 2014.03.25
android blindsview  (0) 2014.03.25
Drag And Drop GridView use Adapter  (0) 2014.03.25
회전목마 리스트  (0) 2014.03.20
라운드 이미지뷰  (0) 2014.03.18
블로그 이미지

날기억해

Android / IOS / PHP / System Engineer / Service Architecture/ MongoDB / AWS / Mysql / Linux / Python / C++ / Vue.js / node.js / Java / Iot / BLE / Firebase / Bigdata Architecture / AD Server / SDK / Epub /

,

DynamicGrid

Drag and drop GridView for Android provide mechanism to reorder grid items

Demo

example

Requrements

Rearranging items require api 8 (Froyo). All grid item animations require api 11 (Honeycomb).

Usage

Usage same as for normal GridView except adapter. Adapter must extends AbstractDynamicGridAdapter orBaseDynamicGridAdapter

gridView = (DynamicGridView) findViewById(R.id.dynamic_grid);
// pass to adapter context, list of items and number of columns count
gridView.setAdapter(new MyDynamicGridAdapter(this, itemsList, 3));

To start Drag'n'drop mode:

gridView.startEditMode();

To stop:

gridView.stopEditMode();

Adding drop listener:

gridView.setOnDropListener(new DynamicGridView.OnDropListener(){
    @Override
    public void onActionDrop(){
        // stop edit mode immediately after drop item
        gridView.stopEditMode();
        }
    });

You can find more detailed usage examle here.

Credits

DynamicGridView based on Daniel Olshansky ListView cell dragging and rearranging video.


https://github.com/askerov/DynamicGrid

'IT > Android' 카테고리의 다른 글

android blindsview  (0) 2014.03.25
HeaderGridView  (0) 2014.03.25
회전목마 리스트  (0) 2014.03.20
라운드 이미지뷰  (0) 2014.03.18
리스트뷰 아이템 위치 바꾸기  (0) 2014.03.18
블로그 이미지

날기억해

Android / IOS / PHP / System Engineer / Service Architecture/ MongoDB / AWS / Mysql / Linux / Python / C++ / Vue.js / node.js / Java / Iot / BLE / Firebase / Bigdata Architecture / AD Server / SDK / Epub /

,

라운드 이미지뷰

IT/Android 2014. 3. 18. 11:58

RoundedImageView

A fast ImageView (and Drawable) that supports rounded corners (and ovals or circles) based on the originalexample from Romain Guy

RoundedImageView screenshotRoundedImageView screenshot with ovals

There are many ways to create rounded corners in android, but this is the fastest and best one that I know of because it:

  • does not create a copy of the original bitmap
  • does not use a clipPath which is not hardware accelerated and not anti-aliased.
  • does not use setXfermode to clip the bitmap and draw twice to the canvas.

If you know of a better method, let me know and I'll implement it!

Also has proper support for:

  • Borders (with Colors and ColorStateLists)
  • Ovals and Circles
  • All ScaleTypes
    • Borders are drawn at view edge, not bitmap edge.
    • Except on edges where the bitmap is smaller than the view
    • Borders are not scaled up/down with the image (correct width and radius are maintained)
  • Anti-aliasing
  • Transparent backgrounds
  • Hardware acceleration
  • Support for LayerDrawables (including TransitionDrawables)

Gradle

RoundedImageView is available on Maven Central.

Add the following to your build.gradle to use:

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.makeramen:roundedimageview:1.2.4'
}

Maven (Deprecated)

Make sure you installed Android 4.2 from the Android Maven Deployer

Build the apk:

git clone https://github.com/vinc3m1/RoundedImageView.git
cd ./RoundedImageView/
mvn clean install

Install and run:

cd ./example
mvn android:deploy android:run

If you want to use the library, add this dependency:

<dependency>
    <groupId>com.makeramen</groupId>
    <artifactId>roundedimageview-apklib</artifactId>
    <version>1.2.0</version>
    <type>apklib</type>
</dependency>

Usage

Define in xml:

<com.makeramen.RoundedImageView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/imageView1"
        android:src="@drawable/photo1"
        android:scaleType="centerCrop"
        app:corner_radius="30dip"
        app:border_width="2dip"
        app:border_color="#333333"
        app:round_background="true"
        app:is_oval="true" />

Or in code:

RoundedImageView iv = new RoundedImageView(context);
iv.setScaleType(ScaleType.CENTER_CROP);
iv.setCornerRadius(10);
iv.setBorderWidth(2);
iv.setBorderColor(Color.DKGRAY);
iv.setRoundedBackground(true);
iv.setImageDrawable(drawable);
iv.setBackground(backgroundDrawable);
iv.isOval(true);

ChangeLog

  • 1.2.4

    • add basic support for ColorDrawable (and other drawables with -1 intrinsic dimens)
    • implementation of the above is known to be buggy in many cases, pull requests welcome
  • 1.2.3

    • added rudimentary support for setImageUri. Performance of the function is probably poor and users should be cautious when using it.
  • 1.2.2

    • fix for incorrect radius on the image when there is a border
    • add a toBitmap() function for easier Picasso and Ion compatibility
  • 1.2.1

    • default scaleType now FIT_CENTER (and never null) to match Android (#27)
  • 1.2.0

    • add setDither and setFilterBitmap method support on RoundedDrawable for tuning bitmap scaling quality
    • improved performance for setImageResource
    • RoundedDrawable constructor is now public
    • Fixed bug where artifact was downloading aar.asc file instead of aar. You no longer need to have @aar specified in the dependency
  • 1.1.0

    • LayerDrawable support (needs testing!)
    • Refactored api to support chaining and remove repetitive code
  • 1.0.0

    • Initial release to maven central
    • Programmatically setting attributes with TransitionDrawables not supported.


https://github.com/vinc3m1/RoundedImageView


블로그 이미지

날기억해

Android / IOS / PHP / System Engineer / Service Architecture/ MongoDB / AWS / Mysql / Linux / Python / C++ / Vue.js / node.js / Java / Iot / BLE / Firebase / Bigdata Architecture / AD Server / SDK / Epub /

,

FRIDAY, JUNE 7, 2013

DevBytes: Custom Activity Animations

It's Friday: time for another DevBytes.

It's been a while, but they're back. At least until the queue runs out again and I write another glut of demos to talk about.

This episode, and most of the upcoming ones (teaser alert!) are around demos/code that we showed in A Moving Experience, the animation talk that +Romain Guy and I gave at Google I/O 2013.

Custom Activity Animations:
Window animations provide an easy way to animate transitions between activities. The animations can be customized to some extent, but there's only so much interaction between the launching and launched activities that you can take advantage of with the standard window animations.
This episode covers a different technique for fully customizable animations.

Video: http://www.youtube.com/watch?v=CPxkoe2MraA

Code: http://developer.android.com/shareables/devbytes/ActivityAnimations.zip


'IT > Android' 카테고리의 다른 글

라운드 이미지뷰  (0) 2014.03.18
리스트뷰 아이템 위치 바꾸기  (0) 2014.03.18
테블릿 레이아웃 샘플  (0) 2014.03.18
[Android] WebView Can miss Content temporarily  (0) 2013.06.19
[Android] NDK (JNI파일 만들기)  (0) 2012.05.23
블로그 이미지

날기억해

Android / IOS / PHP / System Engineer / Service Architecture/ MongoDB / AWS / Mysql / Linux / Python / C++ / Vue.js / node.js / Java / Iot / BLE / Firebase / Bigdata Architecture / AD Server / SDK / Epub /

,