Android的水平滚动的图片库 [英] Android Horizontal scrolling image gallery
问题描述
我想与水平图片库(有一个行和多列)创建应用程序。
首先我尝试使用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?
推荐答案
里面HorizontalScrollView创建的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屋!