Fancycoverflow布局工作不正常 [英] Fancycoverflow layout is not working properly

查看:785
本文介绍了Fancycoverflow布局工作不正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序添加花哨的Cover Flow功能,它工作正常,但问题是,看中的Cover Flow的观点是古怪的显示。

我按照这个例子 https://github.com/davidschreiber/FancyCoverFlow

我想是这样的。

但输出我得到是这样的

我的意思是在同一时间只有个PIC是显示在屏幕上,在任何一方我不能够看到下一张图片

MyAdapter

 类CoverAdapter扩展FancyCoverFlowAdapter {
        私人LayoutInflater充气;
        公共活性;
        查看六;
        公众的ArrayList< HashMap的<字符串,字符串>> ARR;
        公众的ArrayList< HashMap的<字符串,字符串>>数据;

        公共CoverAdapter(活动homeActivity,ArrayList的< HashMap的<字符串,字符串>> myList中){

            ARR = myList中;
            A = homeActivity;
            充气=(LayoutInflater)a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        @覆盖
        公众诠释getCount将(){
            返回arr.size();
        }

        @覆盖
        公共对象的getItem(INT位置){
            // TODO自动生成方法存根
            返回的位置;
        }

        @覆盖
        众长getItemId(INT位置){
            // TODO自动生成方法存根
            的System.out.println(位置=+位置);
            返回的位置;
        }

        @覆盖
        公共查看getCoverFlowItem(INT位置,查看convertView,ViewGroup中父){
            Log.d(AAA位置+);
            查看VI = convertView;
            如果(六== NULL)
                VI = inflater.inflate(R.layout.create_club_inflate,NULL);

            TextView的日期1 =(TextView中)vi.findViewById(R.id.txtDate1);
            TextView的日期=(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的地面=(TextView中)vi.findViewById(R.id.txt_time);

            HashMap的<字符串,字符串>产品=新的HashMap<字符串,字符串>();
            产品= arr.get(位置);

            的System.out.println(名1 =+ product.get(str_team1_name)+团队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.createFromAsset(getAssets(),TitilliumText22L006.otf);

            INT []色= {Color.rgb(100,100,100),Color.rgb(255,255,255)};
            浮[] color_position = {0,1};
            TILEMODE tile_mode = TileMode.MIRROR; //或TileMode.REPEAT;
            的LinearGradient lin_grad =新的LinearGradient(0,0,0,50,颜色,color_position,tile_mode);
            着色器shader_gradient = lin_grad;
            team1_name.getPaint()setShader(shader_gradient)。
            team2_name.getPaint()setShader(shader_gradient)。
            team1_name.setTypeface(字体);
            team2_name.setTypeface(字体);
            ground.setText(product.get(str_grnd));

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


            串first_team_id = product.get(str__team1_id);
            串second_team_id = product.get(str_team2_obj_id);


            返回六;
        }
 

解决方案

请看看下面的code:

 公共类MyDemoActivity延伸活动{

// ================================================ =============================
//超类型覆盖
// ================================================ =============================

@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.layout_inflate_example);

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

    fancyCoverFlow.setAdapter(新ViewGroupExampleAdapter());
}

// ================================================ =============================
//私有类
// ================================================ =============================

私有静态类ViewGroupExampleAdapter扩展FancyCoverFlowAdapter {

    // ================================================ =============================
    //私有成员
    // ================================================ =============================

    私人INT []的图像= {R.drawable.image1,R.drawable.image2,R.drawable.image3,R.drawable.image4,R.drawable.image5,R.drawable.image6,};

    // ================================================ =============================
    //超类型覆盖
    // ================================================ =============================

    @覆盖
    公众诠释getCount将(){
        返回images.length;
    }

    @覆盖
    公共整数的getItem(int i)以{
        返回图像[我]
    }

    @覆盖
    众长getItemId(int i)以{
        返回我;
    }

    @覆盖
    公共查看getCoverFlowItem(INT I,查看reuseableView,ViewGroup中的ViewGroup){
        CustomViewGroup customViewGroup = NULL;

        如果(reuseableView!= NULL){
            customViewGroup =(CustomViewGroup)reuseableView;
        } 其他 {
            customViewGroup =新CustomViewGroup(viewGroup.getContext());
            customViewGroup.setLayoutParams(新FancyCoverFlow.LayoutParams(300,600));
        }

        。customViewGroup.getImageView()setImageResource(this.getItem(ⅰ));

        返回customViewGroup;
    }
}

私有静态类CustomViewGroup扩展的LinearLayout {

    // ================================================ =============================
    //子视图
    // ================================================ =============================

    私人ImageView的ImageView的;

    私人Button按钮;

    // ================================================ =============================
    //构造函数
    // ================================================ =============================

    私人CustomViewGroup(上下文的背景下){
        超(上下文);

        this.setOrientation(垂直);
        this.setWeightSum(5);

        this.imageView =新ImageView的(上下文);
        this.button =新按钮(上下文);

        的LayoutParams的LayoutParams =新的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(真正的);

        this.button.setText(转到GitHub上);
        this.button.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(视图查看){
                意图I =新的意图(Intent.ACTION_VIEW,Uri.parse(https://davidschreiber.github.com/FancyCoverFlow));
                。view.getContext()startActivity(ⅰ);
            }
        });

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

    // ================================================ =============================
    //吸气剂
    // ================================================ =============================

    私人ImageView的getImageView(){
        返回ImageView的;
    }
}
}
 

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

but the output i am getting is like this

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;
        }

解决方案

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;
    }
}
}

这篇关于Fancycoverflow布局工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆