问题
May be i am asking wrong question. But please guys help me out. i want to display images in Grid View format. I have 5 images now i want to display these images like this(in single row scroll able).
image1 image2 image3 image4 image5
But in mobile we can display 2 or 3 at a time. Can we set the number of rows in Grid View like numColumn:2
?
Thanks for considering.
回答1:
If you need to display a fixed number of images (for example using ImageView
) horizontally, the best solution is using HorizontalScrollView
with a single horizontal LinearLayout
child, which will contain the images. It will look something like this:
<HorizontalScrollView android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView ...
... />
<ImageView ...
... />
...
</LinearLayout>
</HorizontalScrollView>
回答2:
GridView
is not really designed for this purpose, it is designed to display an indefinite amount of data in an efficient scrolling manner. If you want to create a static layout where you can discretely place items at specific locations, you should be looking at GridLayout
or TableLayout
instead.
from
How to set a fixed number of rows in android gridView?
来源:https://stackoverflow.com/questions/20748126/is-there-anyway-to-set-the-no-of-row-in-gridview-android