Android的水平滚动的图片库 [英] Android Horizontal scrolling image gallery

查看:95
本文介绍了Android的水平滚动的图片库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想与水平图片库(有一个行和多列)创建应用程序。
首先我尝试使用gridview的,但它可以作为仅垂直滚动。
我可以使用的ListView GridView控件为目的?

I'd like to create app with horizontal image gallery (with one row and multiple columns). First i try to use gridview, but it can be used as vertical scroll only. Can i use ListView or GridView for that purposes?

推荐答案

里面Horizo​​ntalScrollView创建的LinearLayout,然后动态创建的ImageView和ImageView的增加的LinearLayout。

create LinearLayout inside HorizontalScrollView,then create an imageView dynamically and add that imageview to linearLayout.

举例code:

<HorizontalScrollView 
android:id="@+id/horizontal_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

    <LinearLayout
    android:id="@+id/linear"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    </LinearLayout>

</HorizontalScrollView>

在onCreate()方法,从XML文件中获得的LinearLayout的ID和动态创建的ImageView添加到LinearLayout中:

In onCreate() method,get the id of linearLayout from the xml file and add dynamically created ImageView to linearlayout:

    LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
    for (int i = 0; i < 10; i++) {
        ImageView imageView = new ImageView(this);
        imageView.setId(i);
        imageView.setPadding(2, 2, 2, 2);
        imageView.setImageBitmap(BitmapFactory.decodeResource(
                getResources(), R.drawable.ic_launcher));
        imageView.setScaleType(ScaleType.FIT_XY);
        layout.addView(imageView);
    }

这篇关于Android的水平滚动的图片库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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