Search Google

Tuesday, 20 January 2015

all about android studio and android design like facebook

 find your apk file in :-
AndroidStudioProjects\zoopmobile\app\build\outputs\apk   PSD DESIGN

There are three ways to generate your build as per the buildType. (In your case, it's release but it can be named anything you want.)
  1. Go to Gradle Task in right panel of Android Studio and search for assembleRelease or assemble(#your_defined_buildtype) under Module Tasks
  2. Go to Build Variant in Left Panel and select the build from drop down
  3. Go to project root directory in File Explore and open cmd/terminal and run:
    Linux: ./gradlew assembleRelease or assemble(#your_defined_buildtype)
    Windows: gradlew assembleRelease or assemble(#your_defined_buildtype)
If you want to do a release build (only), you can use Build > Generate Signed apk. For other build types, only the above three options are available.
You can find the generated APK in your module/build directory having the build type name in it.
You can use this code
android {
signingConfigs {
        release {
            storeFile file("../your_key_store_file.jks")
            storePassword "some_password"
            keyAlias "alias_name"
            keyPassword "key_password"

    buildTypes {

        release {
            signingConfig signingConfigs.release

then from your terminal run
gradle assembleRelease
you will get the apk at
Complete Tutorial -> How To Generate Signed APK with Gradle Task

Android Studio error installing Gradle

Please read the log from:
  • On Microsoft Windows: [Windwos Drive]\Documents and Settings\[your username]\.AndroidStudioPreview\system\log
  • On Mac and Linux: ~/.AndroidStudioPreview/system/log/
And you will find the tmp download path of For example, mine is:
2013-05-17 09:42:16,934 [ 283002]   INFO - ution.rmi.RemoteProcessSupport - Unzipping C:\Documents and Settings\Kiki.J.Hu\.gradle\wrapper\dists\gradle-1.6-bin\72srdo3a5eb3bic159kar72vok\ to C:\Documents and Settings\Kiki.J.Hu\.gradle\wrapper\dists\gradle-1.6-bin\72srdo3a5eb3bic159kar72vok 
Caused by: com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not install Gradle distribution from ''. error in opening zip file
So I know the cause: I downloaded an incomplete ZIP package.
Then I downloaded the full ZIP package from manually and copied this ZIP package to:
  • Windows: C:\Documents and Settings\Kiki.J.Hu\.gradle\wrapper\dists\gradle-1.6-bin\72srdo3a5eb3bic159kar72vok\
  • Mac OS X: ~/.gradle/wrapper/dists/gradle-1.10-all/6vpvhqu0efs1fqmqr2decq1v12/
Everything is OK now.

How to include support library?
Another great thing that announced in Google I/O 2013 is ActionBar Compat. I’m waiting it for a long time, because using “Sherlock ActionBar” is a little bit complicated. And now it’s released. Download it with your SDK Manager.
Then include it in your project. How? Because this is Gradle-based, it’s quite simple. Open “build.gradle” in your main project folder.
For Android-Support v4:
– It’s automatically included when you created new project. But if not, use second step.
– Add this line:
dependencies {

compile “”

For Android-Support v7:
– Add this line:
dependencies {

compile “”

How tot test your app?
Just like Eclipse, Android Studio support 2 way of testing. By using AVD (Android Virtual Devices) or by real devices. To edit configurations, go to “Run” -> “Edit Configurations”. I recommend you to choose “Target Device” -> “Show chooser dialog”, to give you more freedom in testing.

For AVD:
– You have to create at least one AVD. To create AVD, go to “Tools” -> “Android” -> “AVD Manager”
– In the chooser dialog, select AVD, and choose your devices.
For Real Device:
– You have to enable USB Debugging in your devices! Enable it, then go forward.
– Connect it through USB. In chooser dialog, you will see your device there.
Known issue: Sometimes the driver is not right. You should use Google USB Driver for testing app in Android. Or sometime, your device won’t be detected if it’s in sleep/locked mode.

How to generate a signed APK?
This is also easy! Android Studio is provided with App-signing capability so you don’t have to open up your keytool or do somewhat-complicated task.
Here’s some steps:
– Go to “Build” -> “Generate Signed APK…”
– Click “Create new…”

– To make a new keystore, just put a non-exist keystore in “Key store path:” (The folder MUST exist, while the file MUST NOT exist). And other details.

– It will automatically completed our last dialog in keystore. Just click “Next”

– And “Finish”

If you want to change to Darcula Look and Feel, (in Windows) just press: “Ctrl + ~” -> “Switch Look and Feel” -> “Darcula”.
This look and feel is very interesting, and I like it so much.

Facebook Android App like UI

I did something like below: enter image description here
enter image description here
Below is my code for something like facebook side menu bar
  1. I put 2 views overlap in a frame layout. The bottom view is the menu, the top view is the content body.
  2. And I put the content body into a horizantal scroll view. I also put a view to the left of the content body in the horizantal scroll view. And set the view's background as transparent.
  3. Then scroll to content body at begining. So the side menu bar is blocked by the content body.
  4. When click a button to show the menu, I scroll the horizantal scroll view to show the transparent placeholder. Then the menu will show up since it is under the transparent placeholder now.
I did not use XML for the interface. I create everything in the below code. I think it should be easy to read and put into your eclipse.
package com.chaoshen.androidstudy.facebooklikesidemenubar;

import android.os.Bundle;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity{

    private boolean Menu_Displayed=false;

    public void onCreate(Bundle savedInstanceState) {

        Display display = getWindowManager().getDefaultDisplay();
        final int width = display.getWidth();

        // menu:
        LinearLayout li_menu = new LinearLayout(this);
        li_menu.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  
        li_menu.setOrientation(1);//1 is vertical

        Button btn1 = new Button(this);
        btn1.setText("button 1");
        btn1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));  


        final HorizontalScrollView hsv = new HorizontalScrollView(this){
            // do not let hsv consume the click itself. Then the view under the hsv will also consume the click
            //so that the menu will be clicked
            //when menu is not showed up, let hsv be the only view to consume the click.
            //so that the menu will not be clicked
            public boolean onTouchEvent(MotionEvent ev) {
                    return false;
                    return true;
        hsv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  

        final LinearLayout li_body = new LinearLayout(this);
        li_body.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));  
        li_body.setOrientation(0);//0 is horizantal


        //body: place holder transparent
        TextView placeholder = new TextView(this);
        placeholder.setLayoutParams(new LayoutParams(width-100, LayoutParams.FILL_PARENT));  

        //body: real content
        LinearLayout li_content = new LinearLayout(this);
        li_content.setLayoutParams(new LayoutParams(width, LayoutParams.FILL_PARENT));  
        li_content.setOrientation(1);//1 is vertical

        TextView tv1 = new TextView(this);  
        tv1.setText("txt 1");  

        TextView tv2 = new TextView(this);  
        tv2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));  
        tv2.setText("txt 2");  

        //use this button to scroll
        Button btn_showMenu = new Button(this);
        btn_showMenu.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        btn_showMenu.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
       Runnable() {

                    public void run() {
                            hsv.smoothScrollTo(width-100, 0);
                            hsv.smoothScrollTo(0, 0);
                        Menu_Displayed = !Menu_Displayed;



        //add menu and body in to frame
        FrameLayout mainFrame = new FrameLayout(this);  
        mainFrame.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  

        //scroll to the body real content to block the menu Runnable() {

            public void run() {
                hsv.scrollBy(width-100, 0);             



Android sidebar like facebook or firefox


Android Facebook style slide


Use SideNavigationView for side menu like facebook. But you will need a library for this which you can download from here "".
Code for using it is:
SideNavigationView  sideNavigationView;
sideNavigationView = (SideNavigationView)findViewById(;
Now, make menu you want to show in Slide menu.
All the best....

Horizontal facebook style silder

Layout Animation Android[Facebook]


Technical implementation

The side navigation isn't (yet) included in the Android SDK. A quick search in github does reveal one project that has implemented the UI pattern.

android-fb-like-slideout-navigation at github
There's also a video demonstrating the library at work.

EDIT: Here's another library project:
Thanks Mr BuBBLs in comments!

Two more library project:

If you know any other library projects doing this please leave a comment bellow or at the Google+ page!

Cyril Mottier has also written about implementing this pattern in his blog. These posts are very much worth reading:
The making of Prixing #1: Fly-in app menu
The making of Prixing #2: Swiping the fly-in app menu
The making of Prixing #3: Polishing the sliding app menu

See also the Prixing app on the Google Play to try out the side navigation implemented by Cyril.


Ok After spending 2 days reading about similair problems and how people solved them I finally was able to create the thing I wanted. I was not able to do it with 2 diffrent XML files, but I doubt it is not possible.
I did encountert some problems tho.
After the first animation ended, the button was not clickable. This is because the animation shows that everything is moved but it does not update the layout, so the button is still at the position where the animation started. So I had to calculate the new position of the layout.
I think I read somewhere that this is no longer an issue in 3.0, but correct me if I am wrong
Another was that when I had my animation finally working the way I wanted my underlaying view did disapear before the animation was finished because I invoked view.setVisabilty(View.GONE);. Now the problem was when I did not invoke that method, the animation just hang for a second and then shooter to the end position of the animation. So I added a empty LinearLayout (can be anything) , Default property on GONE, when the animation starts set it on Visible. when you revert the animation, set it again to gone. after doing this the animation was working the way I wanted.
And if you are using a Rel, Linear, or any other layout. then you cant stack views in the Z order so you have to use an SurfaceView.
so heres main.xml
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=""
    android:orientation="vertical" >

        android:layout_height="fill_parent" />

        android:orientation="vertical" >

            android:orientation="vertical" android:visibility="gone">

            android:layout_height="wrap_content" >


            android:layout_alignParentTop="true" android:background="#ff0000" android:layout_margin="2dp">

                android:text="slide" />


heres the java code
    public class MenuAnimationActivity extends Activity {

    private Button buttonSwitch;  
    private View subLayout;
    private View topLayout;
    private ListView subViewListView;
    private String listViewDummyContent[]={"Android","iPhone","BlackBerry","AndroidPeople"};
    private Display display;
    private View fakeLayout;
    private AnimationListener AL;

    // Values for after the animation
    private int oldLeft;
    private int oldTop;
    private int newleft;
    private int newTop;
    private int screenWidth;    
    private int animToPostion; 
    // TODO change the name of the animToPostion for a better explanation.

    private boolean menuOpen = false;

        /** Called when the activity is first created. */  
        public void onCreate(Bundle savedInstanceState) {  

            buttonSwitch = (Button)findViewById(;  
            subLayout = (View) findViewById(;  
            topLayout = (View) findViewById(;
            fakeLayout = (View)findViewById(;

            subViewListView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , listViewDummyContent));

            display =  getWindowManager().getDefaultDisplay();
            screenWidth = display.getWidth();
            int calcAnimationPosition = (screenWidth /3);

            // Value where the onTop Layer has to animate
            // also the max width of the layout underneath 
            // Set Layout params for subLayout according to calculation
            animToPostion = screenWidth - calcAnimationPosition;

            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(animToPostion, RelativeLayout.LayoutParams.FILL_PARENT);

             topLayout.setOnTouchListener(new OnTouchListener() {

                public boolean onTouch(View v, MotionEvent event) {

                        if(event.getAction() == MotionEvent.ACTION_DOWN) {
                            if (menuOpen == true) {

                    return false;

            buttonSwitch.setOnClickListener(new View.OnClickListener() {  

               public void onClick(View v) { 
                   if(menuOpen == false){    
                   } else if (menuOpen == true) {

             AL = new AnimationListener() {

                public void onAnimationStart(Animation animation) {
                public void onAnimationRepeat(Animation animation) {
                    // TODO Auto-generated method stub

                public void onAnimationEnd(Animation animation) {
                    if(menuOpen == true) {
                        Log.d("", "Open");              
                        topLayout.layout(oldLeft, oldTop, oldLeft + topLayout.getMeasuredWidth(), oldTop + topLayout.getMeasuredHeight() );
                        menuOpen = false;
                    } else if(menuOpen == false) {
                        topLayout.layout(newleft, newTop, newleft + topLayout.getMeasuredWidth(), newTop + topLayout.getMeasuredHeight() );                    
                        menuOpen = true;

        public void animSlideRight(){

                newleft = topLayout.getLeft() + animToPostion;
                newTop = topLayout.getTop();    
                TranslateAnimation slideRight = new TranslateAnimation(0,newleft,0,0);

        public void animSlideLeft() {

            oldLeft = topLayout.getLeft() - animToPostion;
            oldTop = topLayout.getTop();        
            TranslateAnimation slideLeft = new TranslateAnimation(newleft,oldLeft,0,0);
I did some extra coding on touching views and stuff.
And the final result
before Animation
enter image description here
after First Animation
enter image description here
And after the second Animation back to the left it states returns as the first Image.
Al those posts that helped me really deserve some credit but I cant find any of them.

No comments:

Post a Comment