轮播 - 减少项目之间的空间

时间:2013-10-08 10:03:36

标签: android carousel

我有一些使用轮播效果显示的图像:

以下是代码:

** carousel_main.xml **          

    <com.digitalaria.gama.carousel.Carousel
        android:id="@+id/carousel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"/>    

</LinearLayout>

** carousel_item.xml **

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

    <ImageView 
        android:id="@+id/itemImage" 
        android:layout_width="match_parent"    
        android:layout_height="match_parent" />

</FrameLayout>

java文件:

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.carousel_main);

    init();
    }

private void init() {
// create the carousel object.
carousel = (Carousel) findViewById(R.id.carousel);

// configurations for the carousel.
carousel.setType(Carousel.TYPE_COVERFLOW);
carousel.setOverScrollBounceEnabled(true);
carousel.setInfiniteScrollEnabled(false);
carousel.setItemRearrangeEnabled(true);

// set images for the carousel.
adapter = new ImageAdapter(this);
carousel.setAdapter(adapter);

// change the first selected position.
carousel.setCenterPosition(3);
}
public class ImageAdapter extends BaseAdapter {
    private Context mContext;

    public ImageAdapter(Context c) {
        mContext = c;
    }

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

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return musicCover[position];
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
        view = LayoutInflater.from(mContext).inflate(R.layout.carousel_item, parent, false);
        view.setLayoutParams(new Carousel.LayoutParams(450, 450));

        ViewHolder holder = new ViewHolder();
        holder.imageView = (ImageView) view.findViewById(R.id.itemImage);

        view.setTag(holder);
        }

        ViewHolder holder = (ViewHolder) view.getTag();
        holder.imageView.setImageResource(musicCover[position]);

        return view;
    }

    private class ViewHolder {
        ImageView imageView;
    }
    }

enter image description here

在图像中,您可以看到左侧,中间和右侧(黑色空间)之间有很多空间。

如果我将view.setLayoutParams(new Carousel.LayoutParams(450, 450));的尺寸增加到600,600,那么左右项将无法显示。

如何解决这个问题?。

0 个答案:

没有答案
相关问题