Display "new stories" Button like Facebook Application by an external library

    Facebook application always has a lot of awesome UI designs, both on the web or mobile apps. If you have read my blog regularly, you will realize that I had some articles about sliding menu like its. Moreover, this application have an another exciting widget which I call "new posts reminding button". It will appear when your newfeed has some new stories, by clicking it, your list view will be updated.
    As you can see, it's interface look like a floating action button. This UI design you also can see at another apps like 9GAG, LinkedIn. Today, in this post, I will provide a simple way to create it: using an third-party library. But I will talk a bit about FloatingActionButton widget (in Design Support library) first.

Weakness of Floating Action Button

    We can find out that the FloatingActionButton always need CoordinatorLayout, we can not put it into place as we would like (here is the top/center of screen) so with this design, FloatingActionButton cannot solve our problem.
    Of course, you can make it yourself but like a lazy programmer like me, I'll use a simple library called PopupBubble, with attaching the PopupBubble button with a RecyclerView, you will done this work easily.

Setting up the library

    In order to use it, adding this dependency to your application level build.gradle:
compile 'com.webianks.library:popup-bubble:1.0.2'
Important Note: your project min-sdk must be 14 or higher to use this library.

Usages

    The object that make the floating action button is PopupBubble. Some important xml attributes are following:
<!--Change background Color-->
    app:backgroundColor="?attr/colorPrimary"
<!--Change text -->
    app:text="New Stories"
<!--Change text color-->
    app:textColor="#ffffff"
<!--Show/Hide Icon inside the button. By default its true.-->
    app:showIcon="false"
<!--Change icon color-->
    app:iconColor="#ffffff"
<!--Set Different Icons-->
    app:setIcon="@drawable/ic_new.png"
In Java code, it has some prominent methods:
  • attaching it with RecyclerView by call setRecyclerView() method
  • By default, it is invisible, show/hide it with call show()/hide()
  • Add listener if you want to know when the bubble is clicked:
  • popupBubble.setPopupBubbleListener(new PopupBubble.PopupBubbleClickListener() {
                @Override
                public void bubbleClicked(Context context) {
                    //popup_bubble is clicked  
                }
            });
    

Sample project code

    Now I will give to readers a sample project about using it. The RecyclerView data will be updated after 10 seconds (add new items) from a background thread (by using Handler). At this moment, the bubble button will appear and if you click on it, you will be redirected to the top (like Facebook app).
Source code for RecyclerView adapter, a simple adapter based on RecyclerView.Adapter:
RecyclerViewAdapter.java
package info.devexchanges.bubblebutton;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.CustomViewHolder> {

    private List<DummyData> list;
    private Context context;

    public RecyclerViewAdapter(Context context, List<DummyData> list) {
        this.list = list;
        this.context = context;
    }


    @Override
    public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler_view, parent, false);

        return new CustomViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(CustomViewHolder holder, @SuppressLint("RecyclerView") final int position) {
        holder.title.setText(list.get(position).getName());
        holder.title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context, "item " + (position + 1) + " clicked!", Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class CustomViewHolder extends RecyclerView.ViewHolder {
        private TextView title;

        public CustomViewHolder(View itemView) {
            super(itemView);

            title = (TextView) itemView.findViewById(R.id.text);
        }
    }
}
    And this is the main activity code:
MainActivity.java
package info.devexchanges.bubblebutton;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.webianks.library.PopupBubble;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


    private List list = new ArrayList<>();
    private RecyclerView recyclerView;
    private PopupBubble popupBubble;
    private RecyclerViewAdapter recyclerViewAdapter;
    private LinearLayoutManager layoutManager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);

        recyclerView.setLayoutManager(layoutManager);
        setDummyData();

        popupBubble = (PopupBubble) findViewById(R.id.popup_bubble);

        //handling onclick bubble button
        popupBubble.setPopupBubbleListener(new PopupBubble.PopupBubbleClickListener() {
            @Override
            public void bubbleClicked(Context context) {
                Toast.makeText(MainActivity.this, "ListView updated!", Toast.LENGTH_SHORT).show();
            }
        });

        //attaching bubble button with recyclerview
        popupBubble.setRecyclerView(recyclerView);

        //add new items from a background thread after 8 seconds
        addNewContent();
    }

    private void setDummyData() {
        DummyData dummyData;
        for (int i = 0; i < 20; i++) {
            dummyData = new DummyData();
            dummyData.setName("RecyclerView item " + (i + 1));
            list.add(dummyData);
        }

        recyclerViewAdapter = new RecyclerViewAdapter(this, list);
        recyclerView.setAdapter(recyclerViewAdapter);
    }

    private void addNewContent() {
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                DummyData data;
                for (int i = 10; i > 0; i--) {
                    data = new DummyData();
                    data.setName("New RecyclerView item " + i);
                    list.add(0, data);
                }
                recyclerViewAdapter.notifyItemRangeInserted(0, 10);
                popupBubble.updateText("10 new items");
                popupBubble.activate();
            }
        }, 10000); //update data after 10 seconds

    }
}
    The main activity layout:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />

    <com.webianks.library.PopupBubble
        android:id="@+id/popup_bubble"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_margin="16dp"
        app:backgroundColor="@color/colorPrimary"
        app:iconColor="#ffffff"
        app:textColor="#ffffff" />

</RelativeLayout>
    Layout for each list view row:
item_recycler_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:text=" Name"
        android:textSize="15sp" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_below="@id/text"
        android:background="#dddddd" />

</RelativeLayout>
    The POJO class of this project:
DummyData.java
package info.devexchanges.bubblebutton;

public class DummyData {

    private String name;

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
}
Running this application, we'll have this output:


Final thoughts

     I had presented a simple solution to make this exciting UI created by Facebook. To deep understanding this library, you can visit it's page on Github and reading the code. In this way, the bubble button is always attached with a RecyclerView, so this is a weakness of this library, too! At the next post, I will provide another solution (customizing it myself) to make this design, coming soon!

Building Sliding Menu like Facebook by a library in Android

    Sliding menu is may be the most popular UI design in mobile application and Android is not also an exception. It's very convenient in switching to the similar feature/choice or simply is changing to another app screen!

    If you follow my blog frequently, you can see that I also had 2 posts about Sliding Menu previously:
  • The first way is using a very famous library from Jeremy Feinstein (Read this post HERE). It's the most popular choice in many applications till now. The weakness of this library is it has not been updated by author and not support for AppCompat themes, depend on ActionBarSherlock, so it's seem obsolete now - when Material Design has affirmed its position, become the official style for Android application.
  • The second way is building a Sliding Menu yourself. It's not too much complicated and if you pay attention to animation, you can create a good one, too! (Read this post HERE).
   By this post, I would like to present one more external library which I think it's quite well in sliding-animation and support well for both left and right side sliding menu and not depend on any theme (so you can build it in a Material Design theme). Implementing it is also not very hard, I'll make a sample project with a screen which have a right-menu (like Facebook application), source code now available on @Github.
    DEMO VIDEO:

Importing library

    Go to library page on Github and clone or download zip file to your computer. After extracting, you will see the 'library' folder
    Importing this folder as an Android module (read my previous post for details), you'll have a new module in your project named library:
    Make sure that your modules build.gradle files have same compileSdkVersion, buildToolsVersion, minSdkVersion,...:
app/build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "info.devexchanges.fbslidingmenu"
        minSdkVersion 14
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile project(':library')
}
library/build.gradle
apply plugin: 'com.android.library'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.0.0'
}

Principles of creating the sliding menu

    In onCreate() of the Activity, firstly, you must initialize a CustomMenu object:
slidingMenu = new CustomMenu(this);
    After that, set content view (main view), shadow drawable and menu view by this code:
//Setting Content Layout
slidingMenu.setContentView(R.layout.activity_main);
slidingMenu.setRightShadow(R.drawable.shadow_right);

//Setting the right menu
ImageView rightMenu = new ImageView(this);
rightMenu.setBackgroundResource(R.drawable.left_view);
customMenu.setRightMenu(rightMenu);
    After all, set this slidingMenu as the content view of your Activity:
setContentView(slidingMenu);
    In the real application, the menu view usually is a ListView, not an ImageView like this. In my project, I will do this.

Demo project: step by step

    Declaring a xml layout contains only a ListView, it will work as the menu view:
layout_right_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#39ac73">

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none" />

</LinearLayout>
    The CustomMenu content view (main view), only a Toolbar and an empty LinearLayout, Fragments will be replaced here later:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="info.devexchanges.fbslidingmenu.MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:orientation="horizontal"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    </android.support.v7.widget.Toolbar>

    <LinearLayout
        android:id="@+id/main_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/toolbar"
        android:orientation="vertical" />
</RelativeLayout>
    In the activity programmatically code, in order to design a "toggle button" in the right side, you must create an option menu file and inflating it to Toolbar. Setting the right menu, shadow like description above and creating the menu data, we have full main activity code:
MainActivity.java
package info.devexchanges.fbslidingmenu;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.Arrays;
import java.util.List;

import cn.tovi.CustomMenu;
import info.devexchanges.fbslidingmenu.fragment.ButtonFragment;
import info.devexchanges.fbslidingmenu.fragment.CheckBoxFragment;
import info.devexchanges.fbslidingmenu.fragment.ImageViewFragment;
import info.devexchanges.fbslidingmenu.fragment.MainFragment;
import info.devexchanges.fbslidingmenu.fragment.RadioGroupFragment;
import info.devexchanges.fbslidingmenu.fragment.SeekBarFragment;
import info.devexchanges.fbslidingmenu.fragment.SwitchFragment;
import info.devexchanges.fbslidingmenu.fragment.TextViewFragment;

public class MainActivity extends AppCompatActivity {

    private Toolbar toolbar;
    private CustomMenu slidingMenu;
    private ListView slidingListView;
    private View rightMenuView;

    private List<String> strings;
    private Fragment currentFragment;

    private final static String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        slidingMenu = new CustomMenu(this);

        //Setting Content Layout
        slidingMenu.setContentView(R.layout.activity_main);
        slidingMenu.setRightShadow(R.drawable.shadow_right);

        //Setting the right menu
        rightMenuView = getLayoutInflater().inflate(R.layout.layout_right_menu, slidingMenu, false);
        slidingListView = (ListView) rightMenuView.findViewById(R.id.list);
        //locate menu in the right
        slidingMenu.setRightMenu(rightMenuView);

        //set content view for activity after all
        setContentView(slidingMenu);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        //setting data for right listview
        setMenuListViewAdapter();

        //handling right listview click listener
        slidingListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                if (position == 2) {
                    replaceFragment(new TextViewFragment());
                } else if (position ==1) {
                    replaceFragment(new ButtonFragment());
                } else if (position == 0) {
                    replaceFragment(new MainFragment());
                } else if (position == 3) {
                    replaceFragment(new ImageViewFragment());
                } else if (position == 4) {
                    replaceFragment(new SwitchFragment());
                } else if (position == 5) {
                    replaceFragment(new CheckBoxFragment());
                } else if (position == 6) {
                    replaceFragment(new RadioGroupFragment());
                } else {
                    replaceFragment(new SeekBarFragment());
                }
                toggleSlidingMenu();
            }
        });

        //replace main fragment when first create activity
        MainFragment fragment = new MainFragment();
        FragmentManager fm = getFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.main_view, fragment);
        ft.commit();
        currentFragment = fragment;
    }

    private void setMenuListViewAdapter() {
        strings = Arrays.asList(getResources().getStringArray(R.array.right_menu));
        ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, strings);
        slidingListView.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.menu) {
            toggleSlidingMenu();
        }
        return super.onOptionsItemSelected(item);
    }

    private void toggleSlidingMenu() {
        if (slidingMenu.getState() == CustomMenu.State.CLOSE_MENU) {
            slidingMenu.openRightMenuIfPossible();
        } else if (slidingMenu.getState() == CustomMenu.State.RIGHT_MENU_OPENS) {
            slidingMenu.closeMenu();
        } else {
            Log.e(TAG, "CustomMenu State:" + slidingMenu.getState());
        }
    }

    private void replaceFragment(Fragment fragment) {
        if (!fragment.getClass().getSimpleName().equals(currentFragment.getClass().getSimpleName())) {
            // Replace fragment main when activity start
            FragmentManager fm = getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.replace(R.id.main_view, fragment);
            ft.addToBackStack("fragment");
            ft.commit();
            currentFragment = fragment;
        }
    }
}
    And this is menu file:
res/menu/menu_main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/menu"
        app:showAsAction="always"
        android:icon="@drawable/menu"
        android:title="Menu" />
</menu>
    As you can see, the MainFragment will be replaced to main view when app start. Other fragments also replaced when user click at any menu view items. It has total 9 fragments in my sample project:
     For example, this is code for ButtonFragment, after click Button here, user will be redirect to other activity:
ButtonFragment.java
package info.devexchanges.fbslidingmenu.fragment;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import info.devexchanges.fbslidingmenu.DetinationActivity;
import info.devexchanges.fbslidingmenu.R;

public class ButtonFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_button, container, false);
        View btnGo = view.findViewById(R.id.btn_go);

        //go to other activity when button clicked
        btnGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), DetinationActivity.class);
                startActivity(intent);
            }
        });

        return view;
    }
}
    And it's layout:
fragment_button.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/activity_horizontal_margin">

    <Button
        android:id="@+id/btn_go"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Go to other Activity" />

</RelativeLayout>
    The "desination activity" code:
DestinationActivity.java

package info.devexchanges.fbslidingmenu;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;

public class DetinationActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_des);
        Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) finish();

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        finish();
    }
}
activity_des.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:orientation="horizontal"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    </android.support.v7.widget.Toolbar>

    <TextView
        android:layout_centerInParent="true"
        android:id="@+id/text_view"
        android:textStyle="bold"
        android:text="Go to here from a Fragment in the Sliding Menu Activity"
        android:padding="@dimen/activity_horizontal_margin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>
    Other fragments code, you can see at my project on Github.
    Strings resource:
strings.xml
<resources>
    <string name="app_name">Sliding Menu like Facebook</string>
    <string name="demo">This is Demo of making Sliding menu like Facebook application</string>

    <string-array name="right_menu">
        <item>MainLayout</item>
        <item>Button</item>
        <item>TextView</item>
        <item>ImageView</item>
        <item>Switch</item>
        <item>CheckBox</item>
        <item>RadioGroup</item>
        <item>SeekBar</item>
    </string-array>
</resources>
    As you see above, I used Toolbar in activities layout, so your app must use a "no Action Bar theme":
styles.xml
<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Running application

    This is our output:
    Menu view is visible (when click toggle button or drag screen):

Conclusions

    By searching on Internet, you may find out another libraries of another ways to make this popular UI and they can work better than this. And once again, through this post, I hope that you have one more choice for designing a sliding menu like Facebook application to apply to your own product.  Moreover, you can visit this tag link to read all posts about Sliding menu. Thanks for reading, readers!
    Reference to the library page: https://github.com/flyfei/CustomMenu

Creating your own sliding menu like Facebook with Material design theme in Android

    There is a library which allows Android developers to easily create applications with slide-in menus like Facebook or LinkedIn made by Jeremy Feinstein, it has been widely used and become very popular. I also had a post about this library in order to guiding my readers to use it. The disadvantages of it is not update the new Android design technology (the last commit was 2 years ago), so if you implement it in your project, you cannot make your app available in Material design style - the new flat-design technology from Google.
    Dealing with this situation, we should find out the way to creating a sliding menu ourself. This post is a tutorial for you about this problem with using some features in Material design technology.
    DEMO VIDEO:

Prerequisites

    After starting a new Android project, make sure that you use a "no Action Bar" theme from Appcompat library with your project:
styles.xml
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Making a sliding layout

    The most important work is designing a "sliding layout", it contains 2 parts: menu view (on the left) and main view (content view). We will let the menu view hold still, while moving the content view. The content view usually sits on top of the menu view and cover the entire screen:
    Name this layout class is SlidingLayout, provide constructors first:
public class SlidingLayout extends LinearLayout {

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

    public SlidingLayout(Context context) {
        super(context);
    }
}
    Now, we'll override some necessary methods. the first is onAttachedToWindow(), called when SlidingLayout is attached to window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called before onDraw(). Here we set child views to our view and content variable:
    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        // Get our 2 children views
        menu = this.getChildAt(0);
        content = this.getChildAt(1);

        // Attach View.OnTouchListener
        content.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return onContentTouch(v, event);
            }
        });

        menu.setVisibility(View.GONE);
    }
    As you can see, we'll handle touching event (gesture) from user in this method to. There are 3 actions we must detect: ACTION_UP, ACTION_DOWN and ACTION_MOVE. When user drag in the content view, the main layout will be scrolled and the menu is displayed a part or whole. This is onContentTouch() method:
public boolean onContentTouch(View v, MotionEvent event) {
        // Do nothing if sliding is in progress
        if (currentMenuState == MenuState.HIDING || currentMenuState == MenuState.SHOWING)
            return false;

        // getRawX returns X touch point corresponding to screen
        // getX sometimes returns screen X, sometimes returns content View X
        int curX = (int) event.getRawX();
        int diffX = 0;

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:

                prevX = curX;
                return true;

            case MotionEvent.ACTION_MOVE:
                // Set menu to Visible when user start dragging the content View
                if (!isDragging) {
                    isDragging = true;
                    menu.setVisibility(View.VISIBLE);
                }

                // How far we have moved since the last position
                diffX = curX - prevX;

                // Prevent user from dragging beyond border
                if (contentXOffset + diffX <= 0) {
                    // Don't allow dragging beyond left border
                    // Use diffX will make content cross the border, so only translate by -contentXOffset
                    diffX = -contentXOffset;
                } else if (contentXOffset + diffX > sldingLayoutWidth - menuRightMargin) {
                    // Don't allow dragging beyond menu width
                    diffX = sldingLayoutWidth - menuRightMargin - contentXOffset;
                }

                // Translate content View accordingly
                content.offsetLeftAndRight(diffX);

                contentXOffset += diffX;

                // Invalite this whole Slidinglayout, causing onLayout() to be called
                this.invalidate();

                prevX = curX;
                lastDiffX = diffX;
                return true;

            case MotionEvent.ACTION_UP:
                // Start scrolling
                // Remember that when content has a chance to cross left border, lastDiffX is set to 0
                if (lastDiffX > 0) {
                    // User wants to show menu
                    currentMenuState = MenuState.SHOWING;

                    // Start scrolling from contentXOffset
                    menuScroller.startScroll(contentXOffset, 0, menu.getLayoutParams().width - contentXOffset,
                            0, SLIDING_DURATION);
                } else if (lastDiffX < 0) {
                    // User wants to hide menu
                    currentMenuState = MenuState.HIDING;
                    menuScroller.startScroll(contentXOffset, 0, -contentXOffset,
                            0, SLIDING_DURATION);
                }

                // Begin querying
                menuHandler.postDelayed(menuRunnable, QUERY_INTERVAL);

                // Invalite this whole Slidinglayout, causing onLayout() to be called
                this.invalidate();

                // Done dragging
                isDragging = false;
                prevX = 0;
                lastDiffX = 0;
                return true;

            default:
                break;
        }
        return false;
    }
    So the main idea of sliding menu is to change contentXOffset and call offsetLeftAndRight for the content to move it.
    We create an enum to control sliding state:
private enum MenuState {
        HIDING, //slidingmenu is collapsing
        HIDDEN, //sliding menu is hidden
        SHOWING, //sliding menu is expanding
        SHOWN, //sliding menu is completely shown
    }
    Using it in toggleMenu() method, allow us to toggle menu:
public void toggleMenu() {
        // Do nothing if sliding is in progress
        if (currentMenuState == MenuState.HIDING || currentMenuState == MenuState.SHOWING)
            return;

        switch (currentMenuState) {
            case HIDDEN:
                currentMenuState = MenuState.SHOWING;
                menu.setVisibility(View.VISIBLE);
                menuScroller.startScroll(0, 0, menu.getLayoutParams().width,
                        0, SLIDING_DURATION);
                break;
            case SHOWN:
                currentMenuState = MenuState.HIDING;
                menuScroller.startScroll(contentXOffset, 0, -contentXOffset,
                        0, SLIDING_DURATION);
                break;
            default:
                break;
        }

        // Begin querying
        menuHandler.postDelayed(menuRunnable, QUERY_INTERVAL);

        // Invalite this whole SlidingLayout, causing onLayout() to be called
        this.invalidate();
    }
    Overriding onMeasure(), we compute menuRightMargin, this variable is the amount of right space the menu should not occupy. In this case, we want the menu to take up 85% amount of the screen width:
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        sldingLayoutWidth = MeasureSpec.getSize(widthMeasureSpec);
        //Sliding menu will take 85% screen size when completely shown
        menuRightMargin = sldingLayoutWidth * 15 / 100;
    }
    The last important method is onLayout(), this is called from layout when this view should assign a size and position to each of its children. This is where we position the menu and content view:
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        // True if SlidingLayout's size and position has changed
        // If true, calculate child views size
        if (changed) {
            // Note: LayoutParams are used by views to tell their parents how they want to be laid out
            // content View occupies the full height and width
            LayoutParams contentLayoutParams = (LayoutParams) content.getLayoutParams();
            contentLayoutParams.height = this.getHeight();
            contentLayoutParams.width = this.getWidth();

            // menu View occupies the full height, but certain width
            LayoutParams menuLayoutParams = (LayoutParams) menu.getLayoutParams();
            menuLayoutParams.height = this.getHeight();
            menuLayoutParams.width = this.getWidth() - menuRightMargin;
        }

        // Layout the child views    
        menu.layout(left, top, right - menuRightMargin, bottom);
        content.layout(left + contentXOffset, top, right + contentXOffset, bottom);
    }
    There are all important methods, adding some necessary features for our own purpose, we have full code for SlidingLayout class:
SlidingLayout.java
package info.devexchanges.slidingmenu;

import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Interpolator;
import android.widget.LinearLayout;
import android.widget.Scroller;

public class SlidingLayout extends LinearLayout {

    // Duration of sliding animation, in miliseconds
    private static final int SLIDING_DURATION = 500;

    // Query Scroller every 16 miliseconds
    private static final int QUERY_INTERVAL = 16;

    // Sliding width
    int sldingLayoutWidth;

    // Sliding menu
    private View menu;

    // Main content
    private View content;

    // menu does not occupy some right space
    // This should be updated correctly later in onMeasure
    private static int menuRightMargin = 0;

    // The state of menu
    private enum MenuState {
        HIDING,
        HIDDEN,
        SHOWING,
        SHOWN,
    }

    // content will be layouted based on this X offset
    // Normally, contentXOffset = menu.getLayoutParams().width = this.getWidth - menuRightMargin
    private int contentXOffset;

    // menu is hidden when initializing
    private MenuState currentMenuState = MenuState.HIDDEN;

    // Scroller is used to facilitate animation
    private Scroller menuScroller = new Scroller(this.getContext(),
            new EaseInInterpolator());

    // Used to query Scroller about scrolling position
    // Note: The 3rd paramter to startScroll is the distance
    private Runnable menuRunnable = new MenuRunnable();
    private Handler menuHandler = new Handler();

    // Previous touch position
    int prevX = 0;

    // Is user dragging the content
    boolean isDragging = false;

    // Used to facilitate ACTION_UP 
    int lastDiffX = 0;

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

    public SlidingLayout(Context context) {
        super(context);
    }

    // Overriding LinearLayout core methods
    // Ask all children to measure themselves and compute the measurement of this
    // layout based on the children
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        sldingLayoutWidth = MeasureSpec.getSize(widthMeasureSpec);
        //Sliding menu will take 85% screen size when completely shown
        menuRightMargin = sldingLayoutWidth * 15 / 100;
    }

    // This is called when SlidingLayout is attached to window
    // At this point it has a Surface and will start drawing. 
    // Note that this function is guaranteed to be called before onDraw
    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        // Get our 2 children views
        menu = this.getChildAt(0);
        content = this.getChildAt(1);

        // Attach View.OnTouchListener
        content.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return onContentTouch(v, event);
            }
        });

        menu.setVisibility(View.GONE);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        // True if SlidingLayout's size and position has changed
        // If true, calculate child views size
        if (changed) {
            // Note: LayoutParams are used by views to tell their parents how they want to be laid out
            // content View occupies the full height and width
            LayoutParams contentLayoutParams = (LayoutParams) content.getLayoutParams();
            contentLayoutParams.height = this.getHeight();
            contentLayoutParams.width = this.getWidth();

            // menu View occupies the full height, but certain width
            LayoutParams menuLayoutParams = (LayoutParams) menu.getLayoutParams();
            menuLayoutParams.height = this.getHeight();
            menuLayoutParams.width = this.getWidth() - menuRightMargin;
        }

        // Layout the child views    
        menu.layout(left, top, right - menuRightMargin, bottom);
        content.layout(left + contentXOffset, top, right + contentXOffset, bottom);
    }

    // Custom methods for SlidingLayout
    // Used to show/hide menu accordingly
    public void toggleMenu() {
        // Do nothing if sliding is in progress
        if (currentMenuState == MenuState.HIDING || currentMenuState == MenuState.SHOWING)
            return;

        switch (currentMenuState) {
            case HIDDEN:
                currentMenuState = MenuState.SHOWING;
                menu.setVisibility(View.VISIBLE);
                menuScroller.startScroll(0, 0, menu.getLayoutParams().width,
                        0, SLIDING_DURATION);
                break;
            case SHOWN:
                currentMenuState = MenuState.HIDING;
                menuScroller.startScroll(contentXOffset, 0, -contentXOffset,
                        0, SLIDING_DURATION);
                break;
            default:
                break;
        }

        // Begin querying
        menuHandler.postDelayed(menuRunnable, QUERY_INTERVAL);

        // Invalite this whole SlidingLayout, causing onLayout() to be called
        this.invalidate();
    }

    // Query Scroller
    protected class MenuRunnable implements Runnable {
        @Override
        public void run() {
            boolean isScrolling = menuScroller.computeScrollOffset();
            adjustContentPosition(isScrolling);
        }
    }

    // Adjust content View position to match sliding animation
    private void adjustContentPosition(boolean isScrolling) {
        int scrollerXOffset = menuScroller.getCurrX();

        // Translate content View accordingly
        content.offsetLeftAndRight(scrollerXOffset - contentXOffset);

        contentXOffset = scrollerXOffset;

        // Invalite this whole Slidinglayout, causing onLayout() to be called
        this.invalidate();

        // Check if animation is in progress
        if (isScrolling)
            menuHandler.postDelayed(menuRunnable, QUERY_INTERVAL);
        else
            this.onMenuSlidingComplete();
    }

    // Called when sliding is complete
    private void onMenuSlidingComplete() {
        switch (currentMenuState) {
            case SHOWING:
                currentMenuState = MenuState.SHOWN;
                break;
            case HIDING:
                currentMenuState = MenuState.HIDDEN;
                menu.setVisibility(View.GONE);
                break;
            default:
                return;
        }
    }

    // Make scrolling more natural. Move more quickly at the end
    protected class EaseInInterpolator implements Interpolator {
        @Override
        public float getInterpolation(float t) {
            return (float) Math.pow(t - 1, 5) + 1;
        }

    }

    // Is menu completely shown
    public boolean isMenuShown() {
        return currentMenuState == MenuState.SHOWN;
    }

    // Handle touch event on content View
    public boolean onContentTouch(View v, MotionEvent event) {
        // Do nothing if sliding is in progress
        if (currentMenuState == MenuState.HIDING || currentMenuState == MenuState.SHOWING)
            return false;

        // getRawX returns X touch point corresponding to screen
        // getX sometimes returns screen X, sometimes returns content View X
        int curX = (int) event.getRawX();
        int diffX = 0;

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:

                prevX = curX;
                return true;

            case MotionEvent.ACTION_MOVE:
                // Set menu to Visible when user start dragging the content View
                if (!isDragging) {
                    isDragging = true;
                    menu.setVisibility(View.VISIBLE);
                }

                // How far we have moved since the last position
                diffX = curX - prevX;

                // Prevent user from dragging beyond border
                if (contentXOffset + diffX <= 0) {
                    // Don't allow dragging beyond left border
                    // Use diffX will make content cross the border, so only translate by -contentXOffset
                    diffX = -contentXOffset;
                } else if (contentXOffset + diffX > sldingLayoutWidth - menuRightMargin) {
                    // Don't allow dragging beyond menu width
                    diffX = sldingLayoutWidth - menuRightMargin - contentXOffset;
                }

                // Translate content View accordingly
                content.offsetLeftAndRight(diffX);

                contentXOffset += diffX;

                // Invalite this whole Slidinglayout, causing onLayout() to be called
                this.invalidate();

                prevX = curX;
                lastDiffX = diffX;
                return true;

            case MotionEvent.ACTION_UP:
                // Start scrolling
                // Remember that when content has a chance to cross left border, lastDiffX is set to 0
                if (lastDiffX > 0) {
                    // User wants to show menu
                    currentMenuState = MenuState.SHOWING;

                    // Start scrolling from contentXOffset
                    menuScroller.startScroll(contentXOffset, 0, menu.getLayoutParams().width - contentXOffset,
                            0, SLIDING_DURATION);
                } else if (lastDiffX < 0) {
                    // User wants to hide menu
                    currentMenuState = MenuState.HIDING;
                    menuScroller.startScroll(contentXOffset, 0, -contentXOffset,
                            0, SLIDING_DURATION);
                }

                // Begin querying
                menuHandler.postDelayed(menuRunnable, QUERY_INTERVAL);

                // Invalite this whole Slidinglayout, causing onLayout() to be called
                this.invalidate();

                // Done dragging
                isDragging = false;
                prevX = 0;
                lastDiffX = 0;
                return true;

            default:
                break;
        }
        return false;
    }
}

Usage in interface (Activity)

    In the Activity layout, adding SlidingLayout as the root container, the menu view certainly is a ListView and the content view is an empty ViewGroup, we will replace Fragments to it then. The menu icon is located in Toolbar:
activity_main.xml
<info.devexchanges.slidingmenu.SlidingLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- This holds our menu -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <ListView
            android:id="@+id/activity_main_menu_listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffb366"
            android:scrollbars="none" />
    </LinearLayout>

    <!-- This holds our content-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            android:orientation="horizontal"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <ImageView
                android:id="@+id/menu_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/app_name"
                android:onClick="toggleMenu"
                android:src="@drawable/menu" />

            <TextView
                android:id="@+id/title"
                style="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginStart="@dimen/activity_horizontal_margin"
                android:gravity="center"
                android:textColor="@android:color/white" />

        </android.support.v7.widget.Toolbar>

        <!-- Fragments container layout -->
        <FrameLayout
            android:id="@+id/activity_main_content_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>
    </LinearLayout>
</info.devexchanges.slidingmenu.SlidingLayout>
    As you can see, I put an ImageView and a TextView inside Toolbar. They work as a toggle menu button and the title of screens.

Programmatically code

    Your Activity must extend from AppCompatActivity, there is nothing too special in code, we set adapter for the ListView (as the menu view), handling menu item click event by replace the corresponding Fragment to the container layout:
MainActivity.java
package info.devexchanges.slidingmenu;

import android.annotation.SuppressLint;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    // The SlidingLayout which will hold both the sliding menu and our main content
    // Main content will holds our Fragment respectively
    SlidingLayout slidingLayout;

    // ListView menu
    private ListView listMenu;
    private String[] listMenuItems;

    private Toolbar toolbar;
    private TextView title; //page title
    private ImageView btMenu; // Menu button
    private Fragment currentFragment;

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Inflate the mainLayout
        setContentView(R.layout.activity_main);
        slidingLayout = (SlidingLayout) findViewById(R.id.sliding_layout);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        title = (TextView) findViewById(R.id.title);
        setSupportActionBar(toolbar);

        // Init menu
        listMenuItems = getResources().getStringArray(R.array.menu_items);
        listMenu = (ListView) findViewById(R.id.activity_main_menu_listview);
        listMenu.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, listMenuItems));
        listMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                onMenuItemClick(parent, view, position, id);
            }

        });

        // handling menu button event
        btMenu = (ImageView) findViewById(R.id.menu_icon);
        btMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Show/hide the menu
                toggleMenu(v);
            }
        });

        // Replace fragment main when activity start
        FragmentManager fm = MainActivity.this.getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();

        MainFragment fragment = new MainFragment();
        ft.add(R.id.activity_main_content_fragment, fragment);
        ft.commit();

        currentFragment = fragment;
        title.setText("Sliding Menu like Facebook");
    }

    public void toggleMenu(View v) {
        slidingLayout.toggleMenu();
    }

    // Perform action when a menu item is clicked
    private void onMenuItemClick(AdapterView<?> parent, View view, int position, long id) {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        Fragment fragment;

        if (position == 0) {
            fragment = new MainFragment();
            title.setText("Main Screen");
        } else if (position == 1) {
            fragment = new ListViewFragment();
            title.setText("ListView Fragment");
        } else if (position == 2) {
            fragment = new TextViewFragment();
            Bundle args = new Bundle();
            args.putString("KEY_STRING", "This is a TextView in the Fragment");
            fragment.setArguments(args);
            title.setText("TextView Fragment");
        } else {
            fragment = new DummyFragment();
            title.setText("Blank Fragment");
        }

        if(!fragment.getClass().equals(currentFragment.getClass())) {
            // Replace current fragment by this new one
            ft.replace(R.id.activity_main_content_fragment, fragment);
            ft.commit();

            currentFragment = fragment;
        }

        // Hide menu anyway
        slidingLayout.toggleMenu();

    }

    @Override
    public void onBackPressed() {
        if (slidingLayout.isMenuShown()) {
            slidingLayout.toggleMenu();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        getSupportActionBar().setTitle("");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return super.onCreateOptionsMenu(menu);
    }
}
     When running app, you'll have this output:

Coclusions and references

    With ListViewFragment, TextViewFragments and some another necessary files, you can view them on @Github. Through this post, I hope that you can be learned about making a complicated custom view (the sliding menu). This menu type is better Navigation Drawer in Android SDK, the application looks smoother in use.
    References:

Android - Loading and Caching Images with Fresco

    In Facebook app, images loading is performed by Fresco. This is a library written by Facebook developers. It is a powerful system for displaying images in Android applications. It takes care of image loading and display so you don't have to. It's also caching images in memory or internal storage, so we do not have to submit the requests to load images multiple times.
    In this post, I will present an overview of it. Hope everyone can grasp the essentials.
    DEMO VIDEO:

Import Fresco to Android Project

    In order to use it, please add this dependency to your local build.gradle (usually in 'app' module):
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.facebook.fresco:fresco:0.7.0' //fresco dependency
 }

Customizing Images view in xml

    Especially, beside loading online images feature, Fresco also allows users to create multiple image shape like circular image, round corner image and many specially features...
    With SimpleDraweeView class, we can create them by corresponding attributes. For example, this xml can be used to make the circular ImageView through fresco:roundAsCircle:

<com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/circle"
            android:layout_width="130dp"
            android:layout_height="130dp"
            android:layout_gravity="center"
            fresco:roundAsCircle="true" />
    And output maybe like this:
    A normal ImageView with the place holder drawable (the default image when loading process error or happening:

<com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/sdv_image"
            android:layout_width="130dp"
            android:layout_height="130dp"
            android:layout_gravity="center"
            fresco:placeholderImage="@mipmap/ic_launcher" />
    The default output:
    A round corner ImageView:

<com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/round_border"
            android:layout_width="130dp"
            android:layout_height="130dp"
            android:layout_gravity="center"
            fresco:placeholderImage="@mipmap/ic_launcher"
            fresco:roundBottomLeft="true"
            fresco:roundBottomRight="true"
            fresco:roundWithOverlayColor="@color/green"
            fresco:roundedCornerRadius="20dp"
            fresco:roundingBorderColor="@color/red"
            fresco:roundingBorderWidth="4dp" />
    And we have this result:
    Moreover, we also can make an ImageView with progressbar when loading, a retry image which can be invoke reloading when clicked,...A full custom should be like this code:
<com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/full_custom_image"
            android:layout_width="130dp"
            android:layout_height="130dp"
            android:layout_gravity="center"
            fresco:actualImageScaleType="focusCrop"
            fresco:backgroundImage="@color/colorPrimary"
            fresco:fadeDuration="300"
            fresco:failureImage="@drawable/error"
            fresco:failureImageScaleType="centerInside"
            fresco:placeholderImage="@mipmap/ic_launcher"
            fresco:placeholderImageScaleType="fitCenter"
            fresco:pressedStateOverlayImage="@color/red"
            fresco:progressBarAutoRotateInterval="1000"
            fresco:progressBarImage="@drawable/loading"
            fresco:progressBarImageScaleType="centerInside"
            fresco:retryImage="@drawable/retry"
            fresco:retryImageScaleType="centerCrop"
            fresco:roundAsCircle="false"
            fresco:roundBottomLeft="false"
            fresco:roundBottomRight="true"
            fresco:roundTopLeft="true"
            fresco:roundTopRight="false"
            fresco:roundWithOverlayColor="@color/colorPrimaryDark"
            fresco:roundedCornerRadius="1dp"
            fresco:roundingBorderColor="@color/colorAccent"
            fresco:roundingBorderWidth="2dp" />

Initializing in programmatically code

    In the activities of fragment code, we will set up the loading data process. Remember to initializing Fresco first by this line in the activity onCreate() method:
Fresco.initialize(this);
    Important Note: Always invoking this code before calling setContentView().
    When loading image from URL, just call setImageURI(), Fresco will do whole loading data process:
roundBorderImage.setImageURI(imageUri);

Full project code

    In this simple project, there are only one Activity which loading image data from URL, this is full code: MainActivity.java

package info.devexchanges.fresco;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;

public class MainActivity extends AppCompatActivity {

    private Button button;
    private SimpleDraweeView sdvImage;
    private SimpleDraweeView roundBorderImage;
    private SimpleDraweeView circleImage;
    private SimpleDraweeView fullCustomImage;

    private void findViews() {
        button = (Button) findViewById(R.id.button);
        sdvImage = (SimpleDraweeView) findViewById(R.id.sdv_image);
        roundBorderImage = (SimpleDraweeView) findViewById(R.id.round_border);
        circleImage = (SimpleDraweeView) findViewById(R.id.circle);
        fullCustomImage = (SimpleDraweeView) findViewById(R.id.full_custom_image);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Fresco.initialize(this);
        setContentView(R.layout.activity_main);
        findViews();

        final Uri imageUri = Uri.parse("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpfvidFNRG-3nj8ZzFJNC4_AV3pD8p6TkObjdKQMDFZfjfVd9i7fUpF2JaRgulwcDnreFubB73YKy2JBu5K_wgdaxlI3iKqN7fpuEI6EGp-hg83UC26SWHLwBlAkjcP1oGQhw8KreBEqVO/w140-h105-p/fresh_green_grass_bokeh-wallpaper-1024x768.jpg");
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sdvImage.setImageURI(imageUri);
                roundBorderImage.setImageURI(imageUri);
                circleImage.setImageURI(imageUri);
                fullCustomImage.setImageURI(imageUri);
            }
        });
    }
}
    And it's layout, which contains all custom image shapes: activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin">

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Loading Images From URL" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Simple Image"
            android:textStyle="bold" />

        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/sdv_image"
            android:layout_width="130dp"
            android:layout_height="130dp"
            android:layout_gravity="center"
            fresco:placeholderImage="@mipmap/ic_launcher" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:text="Round Corner Image"
            android:textStyle="bold" />

        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/round_border"
            android:layout_width="130dp"
            android:layout_height="130dp"
            android:layout_gravity="center"
            fresco:placeholderImage="@mipmap/ic_launcher"
            fresco:roundBottomLeft="true"
            fresco:roundBottomRight="true"
            fresco:roundWithOverlayColor="@color/green"
            fresco:roundedCornerRadius="20dp"
            fresco:roundingBorderColor="@color/red"
            fresco:roundingBorderWidth="4dp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:text="Circle Image"
            android:textStyle="bold" />

        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/circle"
            android:layout_width="130dp"
            android:layout_height="130dp"
            android:layout_gravity="center"
            fresco:roundAsCircle="true" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:gravity="center"
            android:text="Full Customization Image"
            android:textStyle="bold" />

        <com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/full_custom_image"
            android:layout_width="130dp"
            android:layout_height="130dp"
            android:layout_gravity="center"
            fresco:actualImageScaleType="focusCrop"
            fresco:backgroundImage="@color/colorPrimary"
            fresco:fadeDuration="300"
            fresco:failureImage="@drawable/error"
            fresco:failureImageScaleType="centerInside"
            fresco:placeholderImage="@mipmap/ic_launcher"
            fresco:placeholderImageScaleType="fitCenter"
            fresco:pressedStateOverlayImage="@color/red"
            fresco:progressBarAutoRotateInterval="1000"
            fresco:progressBarImage="@drawable/loading"
            fresco:progressBarImageScaleType="centerInside"
            fresco:retryImage="@drawable/retry"
            fresco:retryImageScaleType="centerCrop"
            fresco:roundAsCircle="false"
            fresco:roundBottomLeft="false"
            fresco:roundBottomRight="true"
            fresco:roundTopLeft="true"
            fresco:roundTopRight="false"
            fresco:roundWithOverlayColor="@color/colorPrimaryDark"
            fresco:roundedCornerRadius="1dp"
            fresco:roundingBorderColor="@color/colorAccent"
            fresco:roundingBorderWidth="2dp" />

    </LinearLayout>
</ScrollView>
    Important Note:
  • Never forget Internet permission in AndroidManifest.xml when working with online data:
    <uses-permission android:name="android.permission.INTERNET"/>
    
  • In xml files, you must declare the android:layout_width and android:layout_height of SimpleDraweeView with real dimension value, instead of match_parent or wrap_content.

More information

    Visiting Fresco official document, you can find out more features of this powerful library like loading image form sd card, image pipeline,...(another advantage of Fresco is a good document). In this post, I've just introduce the basic features. Finally, you can download my project from @Github by clicking the button below.