水平的ListView像谷歌目录 [英] Horizontal ListView like Google Catalogs

查看:108
本文介绍了水平的ListView像谷歌目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何像一个出现在谷歌目录水平列表视图?

how do I make a horizontal list view like the one seen in Google Catalogs?

的大的主区是一个viewpager,但底部行是水平滚动视图与那些可点击项目的列表。我假设它的列表视图,如果它是如何将这样做?

The large main area is a viewpager, but the bottom row is a horizontal scrollview with a list of items that are clickable. I'm assuming its a listview, if it was how would this be done?

我已经使用了开放源码的横向列表视图,也就是在这里的其他问题引用,但它并不能作为顺畅像在这个谷歌应用程序。

I've used the open source "horizontal list view" that is referenced in other questions here, but it does not act as smoothly like the one in this google app.

推荐答案

这绝对是一个画廊!

您可以在这里看到,为确保其自带的SDK图库 - > 见的Youtube影片检查它如何运行流畅;)

You can see here that for sure it's a Gallery that comes with the SDK -> See Youtube video to check how smooth it runs ;)

我对我自己做的Andr​​oid.com的简短说明以供将来参考。我希望你可以用它太:

I've made to myself a short guide from Android.com for future reference. I hope that you can use it too:

1)打开RES /布局/ main.xml中的文件,并插入以下内容:

<?xml version="1.0" encoding="utf-8"?>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gallery"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
/>

2)code插入你的的onCreate()方法:

2) Code to insert on your onCreate() method:

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

    Gallery gallery = (Gallery) findViewById(R.id.gallery);
    gallery.setAdapter(new ImageAdapter(this));

    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show();
        }
    });
}

3)创建了一个名为attrs.xml RES /价值/目录中一个新的XML文件。插入以下内容:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="HelloGallery">
        <attr name="android:galleryItemBackground" />
    </declare-styleable>
</resources>

4)返回到您的.java文件和的onCreate(捆绑)方法之后,定义自定义 ImageAdapter 类:

4) Go back to your .java file and after the onCreate(Bundle) method, define the custom ImageAdapter class:

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

    private Integer[] mImageIds = {
            R.drawable.sample_1,
            R.drawable.sample_2,
            R.drawable.sample_3,
            R.drawable.sample_4,
            R.drawable.sample_5,
            R.drawable.sample_6,
            R.drawable.sample_7
    };

    public ImageAdapter(Context c) {
        mContext = c;
        TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
        mGalleryItemBackground = attr.getResourceId(
                R.styleable.HelloGallery_android_galleryItemBackground, 0);
        attr.recycle();
    }

    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) {
        ImageView imageView = new ImageView(mContext);

        imageView.setImageResource(mImageIds[position]);
        imageView.setLayoutParams(new Gallery.LayoutParams(150, 100));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setBackgroundResource(mGalleryItemBackground);

        return imageView;
    }
}

说吧,code是很简单的,但你可以参考原件和更长的文档这里

这篇关于水平的ListView像谷歌目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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