Reputation: 1791
I want to display 2 images in a Row in GridView
.
I have tried to get the screen size in different ways. For example:
final int h = getResources().getDisplayMetrics().densityDpi;
and set size of the image..
convertView.setLayoutParams(new GridView.LayoutParams(h, h));
But this is not sufficent. If screen is large, then 2 images look very small - like peanut, on a big screen.
Can anyone guide me that for example. Device's screen size is 4 inches in Portrait and I can create 2 images of almost 2 inches each.
here is my gridview xml file
<GridView
android:id="@+id/grid_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alwaysDrawnWithCache="true"
android:clipChildren="true"
android:gravity="center_horizontal"
android:horizontalSpacing="2dp"
android:verticalSpacing="5dp"
android:numColumns="auto_fit"
android:padding="0dp"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
>
</GridView>
Upvotes: 1
Views: 2076
Reputation: 2973
To make equal sized images, make the ImageView
like this SquaredImageView
and if you want Layout
to be of equal size then follow the same method describe on onMeasure
of SquaredImageView
Upvotes: 0
Reputation: 26
add these attributes to your grid android:columnWidth="200dp" android:stretchMode="columnWidth"
Upvotes: 1
Reputation: 3182
It sounds like you're trying to change the images size based on the screen size, if so you should take a look at the supporting multiple screen sizes tutorial. Android already offers that functionality.
Also if you're only displaying two images horizontally you could use a LinearLayout instead, using a GridView is overkill.
Upvotes: 1