Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

android - Fancycoverflow layout is not working properly

I added fancy cover flow in my app,It works fine but the issue is,the view of fancy cover flow is weirdly displaying..

I follow this example https://github.com/davidschreiber/FancyCoverFlow

I want something like this

enter image description here

but the output i am getting is like this

enter image description here

I mean at a time only single pic is displaying on screen,at any side i am not able to see next images

MyAdapter

class CoverAdapter extends FancyCoverFlowAdapter {
        private LayoutInflater inflater;
        public Activity a;
        View vi;
        public ArrayList<HashMap<String, String>> arr;
        public ArrayList<HashMap<String, String>> data;

        public CoverAdapter(Activity homeActivity, ArrayList<HashMap<String, String>> myList) {

            arr = myList;
            a = homeActivity;
            inflater = (LayoutInflater) a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        @Override
        public int getCount() {
            return arr.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            System.out.println("position=" + position);
            return position;
        }

        @Override
        public View getCoverFlowItem(int position, View convertView, ViewGroup parent) {
            Log.d("aaa", position + "");
            View vi = convertView;
            if (vi == null)
                vi = inflater.inflate(R.layout.create_club_inflate, null);

            TextView date1 = (TextView) vi.findViewById(R.id.txtDate1);
            TextView date = (TextView) vi.findViewById(R.id.txtDate);
            TextView team1_name = (TextView) vi.findViewById(R.id.txtTeamName);
            TextView team2_name = (TextView) vi.findViewById(R.id.txtVanue);
            TextView ground = (TextView) vi.findViewById(R.id.txt_time);

            HashMap<String, String> product = new HashMap<String, String>();
            product = arr.get(position);

            System.out.println("name 1= " + product.get("str_team1_name") + " team 2="
                    + product.get("str_team2_obj_name"));
            date1.setText(product.get("str_srs"));
            date.setText(product.get("str_startdt"));
            team1_name.setText(product.get("str_team1_name"));
            team1_name.setAlpha(5000);
            team2_name.setText(product.get("str_team2_obj_name"));
            team2_name.setAlpha(5000);
            Typeface font = Typeface.createFromAsset(getAssets(), "TitilliumText22L006.otf");

            int[] color = { Color.rgb(100, 100, 100), Color.rgb(255, 255, 255) };
            float[] color_position = { 0, 1 };
            TileMode tile_mode = TileMode.MIRROR; // or TileMode.REPEAT;
            LinearGradient lin_grad = new LinearGradient(0, 0, 0, 50, color, color_position, tile_mode);
            Shader shader_gradient = lin_grad;
            team1_name.getPaint().setShader(shader_gradient);
            team2_name.getPaint().setShader(shader_gradient);
            team1_name.setTypeface(font);
            team2_name.setTypeface(font);
            ground.setText(product.get("str_grnd"));

            product.get("str_sName");
            product.get("str_team2_obj_sName");


            String first_team_id = product.get("str__team1_id");
            String second_team_id = product.get("str_team2_obj_id");


            return vi;
        }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please Check out the Following Code:

public class MyDemoActivity extends Activity {

// =============================================================================
// Supertype overrides
// =============================================================================

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.layout_inflate_example);

    FancyCoverFlow fancyCoverFlow = (FancyCoverFlow) findViewById(R.id.fancyCoverFlow);
    fancyCoverFlow.setReflectionEnabled(true);
    fancyCoverFlow.setReflectionRatio(0.3f);
    fancyCoverFlow.setReflectionGap(0);

    fancyCoverFlow.setAdapter(new ViewGroupExampleAdapter());
}

// =============================================================================
// Private classes
// =============================================================================

private static class ViewGroupExampleAdapter extends FancyCoverFlowAdapter {

    // =============================================================================
    // Private members
    // =============================================================================

    private int[] images = {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5, R.drawable.image6,};

    // =============================================================================
    // Supertype overrides
    // =============================================================================

    @Override
    public int getCount() {
        return images.length;
    }

    @Override
    public Integer getItem(int i) {
        return images[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getCoverFlowItem(int i, View reuseableView, ViewGroup viewGroup) {
        CustomViewGroup customViewGroup = null;

        if (reuseableView != null) {
            customViewGroup = (CustomViewGroup) reuseableView;
        } else {
            customViewGroup = new CustomViewGroup(viewGroup.getContext());
            customViewGroup.setLayoutParams(new FancyCoverFlow.LayoutParams(300, 600));
        }

        customViewGroup.getImageView().setImageResource(this.getItem(i));

        return customViewGroup;
    }
}

private static class CustomViewGroup extends LinearLayout {

    // =============================================================================
    // Child views
    // =============================================================================

    private ImageView imageView;

    private Button button;

    // =============================================================================
    // Constructor
    // =============================================================================

    private CustomViewGroup(Context context) {
        super(context);

        this.setOrientation(VERTICAL);
        this.setWeightSum(5);

        this.imageView = new ImageView(context);
        this.button = new Button(context);

        LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        this.imageView.setLayoutParams(layoutParams);
        this.button.setLayoutParams(layoutParams);

        this.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        this.imageView.setAdjustViewBounds(true);

        this.button.setText("Goto GitHub");
        this.button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://davidschreiber.github.com/FancyCoverFlow"));
                view.getContext().startActivity(i);
            }
        });

        this.addView(this.imageView);
        this.addView(this.button);
    }

    // =============================================================================
    // Getters
    // =============================================================================

    private ImageView getImageView() {
        return imageView;
    }
}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...