How to make Android Carousel & CardView View Pager

hey guys.... I started by implementing a simple design view that catains CardView and for each cardview. I Implemented a Fragment used FragmentAdapter that contains multiple fragments that user can swipe that it's is ViewPager.

1. Home Activity

package com.tutorialsee.cardviewpager;

import com.tutorialsee.carouselview.TutorialseeCarouselView;
import com.tutorialsee.viewpager.CarouselLayoutMainActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class HomeActivity extends Activity {
TextView cardview,carousel,carousellayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

cardview = (TextView) findViewById(R.id.cardview);
carousel = (TextView) findViewById(R.id.carousel);
carousellayout = (TextView) findViewById(R.id.carousellayout);
cardview.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent ii=new Intent(getBaseContext(),MainActivity.class);
ii.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(ii);


}
});
carousel.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent ii=new Intent(getBaseContext(),TutorialseeCarouselView.class);
ii.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(ii);


}
});
carousellayout.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent ii=new Intent(getBaseContext(),CarouselLayoutMainActivity.class);
ii.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(ii);

}
});
}
}

2. Main Activity

package com.tutorialsee.cardviewpager;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);

        CardFragmentPagerAdapter pagerAdapter = new CardFragmentPagerAdapter(getSupportFragmentManager(), dpToPixels(2, this));
        ShadowTransformer fragmentCardShadowTransformer = new ShadowTransformer(viewPager, pagerAdapter);
        fragmentCardShadowTransformer.enableScaling(true);

        viewPager.setAdapter(pagerAdapter);
        viewPager.setPageTransformer(false, fragmentCardShadowTransformer);
        viewPager.setOffscreenPageLimit(3);
    }

    /**
     * Change value in dp to pixels
     * @param dp
     * @param context
     * @return
     */
    public static float dpToPixels(int dp, Context context) {
        return dp * (context.getResources().getDisplayMetrics().density);
    }
}

Comments

Email Address: 

Hi i want to add the carousal layout main activity inside the fragment thats my requirement n m stuck there. Please help me to solve this problem.