Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:23:46+00:00 2026-06-02T10:23:46+00:00

Coverview is a widget ive implemented from http://www.inter-fuser.com/2010/02/android-coverflow-widget-v2.html and it works until i want

  • 0

Coverview is a widget ive implemented from http://www.inter-fuser.com/2010/02/android-coverflow-widget-v2.html and it works until i want to use it .xml instead to add buttons and stuff. I have no idea how to link the two and any help would be really appreciated

My main activity:

package cover.flow.test;

import java.io.FileInputStream;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.Bitmap.Config;
import android.graphics.PorterDuff.Mode;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

 public class CoverFlowExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 CoverFlow coverFlow;
 coverFlow = new CoverFlow(this);

 coverFlow.setAdapter(new ImageAdapter(this));

 ImageAdapter coverImageAdapter =  new ImageAdapter(this);

 //coverImageAdapter.createReflectedImages();

 coverFlow.setAdapter(coverImageAdapter);

 coverFlow.setSpacing(-25);
 coverFlow.setSelection(4, true);
 coverFlow.setAnimationDuration(1000);


 setContentView(coverFlow);

}

 public class ImageAdapter extends BaseAdapter {
 int mGalleryItemBackground;
 private Context mContext;

 private FileInputStream fis;

 private Integer[] mImageIds = {
   R.drawable.kasabian_kasabian,
         R.drawable.starssailor_silence_is_easy,
         R.drawable.killers_day_and_age,
         R.drawable.garbage_bleed_like_me,
         R.drawable.death_cub_for_cutie_the_photo_album,
         R.drawable.kasabian_kasabian,
         R.drawable.massive_attack_collected,
         R.drawable.muse_the_resistance,
         R.drawable.starssailor_silence_is_easy
 };

 private ImageView[] mImages;

 public ImageAdapter(Context c) {
  mContext = c;
  mImages = new ImageView[mImageIds.length];
 }
  public boolean createReflectedImages() {
      //The gap we want between the reflection and the original image
      final int reflectionGap = 4;


      int index = 0;
      for (int imageId : mImageIds) {
    Bitmap originalImage = BitmapFactory.decodeResource(getResources(), 
      imageId);
       int width = originalImage.getWidth();
       int height = originalImage.getHeight();


       //This will not scale but will flip on the Y axis
       Matrix matrix = new Matrix();
       matrix.preScale(1, -1);

       //Create a Bitmap with the flip matrix applied to it.
       //We only want the bottom half of the image
       Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0, height/2, width, height/2, matrix, false);


       //Create a new bitmap with same width but taller to fit reflection
       Bitmap bitmapWithReflection = Bitmap.createBitmap(width 
         , (height + height/2), Config.ARGB_8888);

      //Create a new Canvas with the bitmap that's big enough for
      //the image plus gap plus reflection
      Canvas canvas = new Canvas(bitmapWithReflection);
      //Draw in the original image
      canvas.drawBitmap(originalImage, 0, 0, null);
      //Draw in the gap
      Paint deafaultPaint = new Paint();
      canvas.drawRect(0, height, width, height + reflectionGap, deafaultPaint);
      //Draw in the reflection
      canvas.drawBitmap(reflectionImage,0, height + reflectionGap, null);

      //Create a shader that is a linear gradient that covers the reflection
      Paint paint = new Paint(); 
      LinearGradient shader = new LinearGradient(0, originalImage.getHeight(), 0, 
        bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, 
        TileMode.CLAMP); 
      //Set the paint to use this shader (linear gradient)
      paint.setShader(shader); 
      //Set the Transfer mode to be porter duff and destination in
      paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); 
      //Draw a rectangle using the paint with our linear gradient
      canvas.drawRect(0, height, width, 
        bitmapWithReflection.getHeight() + reflectionGap, paint); 

      ImageView imageView = new ImageView(mContext);
      imageView.setImageBitmap(bitmapWithReflection);
      imageView.setLayoutParams(new CoverFlow.LayoutParams(120, 180));
      imageView.setScaleType(ScaleType.MATRIX);
      mImages[index++] = imageView;

      }
   return true;
}

 public int getCount() {
     return mImageIds.length;
 }

 public Object getItem(int position) {
     return position;
 }

 public long getItemId(int position) {
     return position;
 }

 public View getView(int position, View convertView, ViewGroup parent) {

  //Use this code if you want to load from resources
     ImageView i = new ImageView(mContext);
     i.setImageResource(mImageIds[position]);
     i.setLayoutParams(new CoverFlow.LayoutParams(130, 130));
     i.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 

     //Make sure we set anti-aliasing otherwise we get jaggies
     BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
     drawable.setAntiAlias(true);
     return i;

  //return mImages[position];
 }
   /** Returns the size (0.0f to 1.0f) of the views 
  * depending on the 'offset' to the center. */ 
  public float getScale(boolean focused, int offset) { 
    /* Formula: 1 / (2 ^ offset) */ 
      return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset))); 
   } 

 }
 }

My main.xml (this is what ive tries to link but with no luck)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>




<cover.flow.test.CoverFlow
    android:id="@+id/coverflow"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button1"
    android:layout_alignParentTop="true" />


<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="Button" />

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:23:48+00:00Added an answer on June 2, 2026 at 10:23 am

    To link with the view you need something like

    setContentView(R.layout.main);

    and remove the code creating the CoverFlow instance (instead get it with findViewById, etc.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am looking at http://developer.android.com/resources/tutorials/views/hello-gridview.html I created test project with additional logs in
I have an Android Gallery widget that displays several ImageViews with pictures from the
Is it possible to use async image loader from this project http://open-pim.com/tmp/LazyList.zip with Gallery
The default Gallery widget on Android does not recycle views - everytime the view
I'm pretty new to android and I've got a question. I'm playing around with
I'm trying to filter my ListView which is populated with this ArrayAdapter: package me.alxandr.android.mymir.adapters;
I'm trying to develop an Android 3.1 tablet application. This app will have a
I'm using a Gallery widget adapter class to lazy load images in. The images
This is the first time I'm developing an Android application so this question might
I wish to manipulate background colors of selected row in my ListView which from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.