Android Fancycoverflow布局工作不正常

Android Fancycoverflow布局工作不正常,android,fancybox,Android,Fancybox,我在我的应用程序中添加了花式封面流,效果很好,但问题是,花式封面流的视图显示得很奇怪 我遵循这个例子 我想要这样的东西 但我得到的结果是这样的 我的意思是在同一时间只有一张图片显示在屏幕上,在任何一边我都看不到下一张图片 MyAdapter class CoverAdapter extends FancyCoverFlowAdapter { private LayoutInflater inflater; public Activity a;

我在我的应用程序中添加了花式封面流,效果很好,但问题是,花式封面流的视图显示得很奇怪

我遵循这个例子

我想要这样的东西

但我得到的结果是这样的

我的意思是在同一时间只有一张图片显示在屏幕上,在任何一边我都看不到下一张图片

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;
        }
class CoverAdapter扩展了FancyCoverFlowAdapter{
私人充气机;
公共活动a;
视图六;
公共ArrayList arr;
公共阵列列表数据;
公共覆盖范围适配器(活动homeActivity,ArrayList myList){
arr=myList;
a=家庭活动;
充气器=(LayoutInflater)a.getSystemService(Context.LAYOUT\u充气器\u SERVICE);
}
@凌驾
public int getCount(){
返回arr.size();
}
@凌驾
公共对象getItem(int位置){
//TODO自动生成的方法存根
返回位置;
}
@凌驾
公共长getItemId(int位置){
//TODO自动生成的方法存根
系统输出打印项次(“位置=”+位置);
返回位置;
}
@凌驾
公共视图getCoverFlowItem(int位置、视图转换视图、视图组父级){
对数d(“aaa”,位置+”);
视图vi=转换视图;
如果(vi==null)
vi=充气机。充气(R.layout.create_club_充气,空);
TextView date1=(TextView)vi.findviewbyd(R.id.txtDate1);
TextView日期=(TextView)vi.findViewById(R.id.txtDate);
TextView team1_name=(TextView)vi.findViewById(R.id.txtTeamName);
TextView团队2_name=(TextView)vi.findViewById(R.id.txtVanue);
TextView地面=(TextView)vi.findViewById(R.id.txt_时间);
HashMap产品=新的HashMap();
产品=arr.get(位置);
System.out.println(“name 1=“+product.get”(“str\u team1\u name”)+“team 2=”
+获取(“str_team2_obj_name”);
date1.setText(product.get(“str_srs”);
date.setText(product.get(“str_startdt”);
team1_name.setText(product.get(“str_team1_name”);
团队1_name.setAlpha(5000);
team2_name.setText(product.get(“str_team2_obj_name”);
团队2_名称setAlpha(5000);
Typeface font=Typeface.createFromAsset(getAssets(),“TitilliumText22L006.otf”);
int[]color={color.rgb(100100100),color.rgb(255,255,255)};
float[]color_position={0,1};
TileMode tile_mode=TileMode.MIRROR;//或TileMode.REPEAT;
LinearGradient lin\u grad=新的LinearGradient(0,0,0,50,颜色,颜色位置,平铺模式);
着色器着色器\梯度=林\梯度;
team1_name.getPaint().setShader(着色器_渐变);
team2_name.getPaint().setShader(着色器_渐变);
team1_name.setTypeface(字体);
team2_name.setTypeface(字体);
ground.setText(product.get(“str_grnd”);
产品获取(“stru sName”);
产品获取(“str_team2_obj_sName”);
字符串first_team_id=product.get(“str_team 1_id”);
字符串second_team_id=product.get(“str_team2_obj_id”);
返回vi;
}

请查看以下代码:

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

嗨,Roman,你从哪里得到源代码?我会很快回复@Roman,你需要mainactivity的代码吗?嗨@Roman,你是否检查了一个完整的示例,其中有ViewGroupExample,可能满足了你的要求