2

I am trying to show several images in an activity.And user can view them by scrolling.I have done this by adding two ImageView for two image.But there is huge space/gap between two images This is looking very unsmart.How can I solve this problem.

Can I make one ImageView to show several images and obviously not using GridView.

My .xml code is here:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/circle" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/circle2" />

    </LinearLayout>

</ScrollView>
Ziem
  • 6,579
  • 8
  • 53
  • 86
Sawpno
  • 85
  • 1
  • 2
  • 10

2 Answers2

0

Try using the scaleType attribute in your ImageViews, as that will make it fill the size of the view. Something like this:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:scaleType="fitXY"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/circle" />

    <ImageView
        android:id="@+id/imageView2"
        android:scaleType="fitXY"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/circle2" />

</LinearLayout>

</ScrollView>
memoizr
  • 2,081
  • 2
  • 18
  • 24
  • scaleType attrubute is working for removing the gap between the images.But this time (using scaleType attribute) the left & right portion of the images are cut up.Now what to do to remove this problem? – Sawpno May 25 '15 at 19:34
  • OK, try using `scaleType="fitXY"`. Here's the documentation of ScaleType for more info: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html – memoizr May 25 '15 at 19:38
  • Is there any way that I can show several images in one imageview? want the next Image will appear on sliding. – Sawpno May 25 '15 at 19:44
  • Cool! I updated my answer. If you found it useful, please mark the answer as "accepted". With regards to multiple imageviews, that's for another question, as it's not super trivial! :) – memoizr May 25 '15 at 19:46
0
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1">

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:src="@drawable/icon"
            android:layout_weight="0.4"/>

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:src="@drawable/icon"
            android:layout_weight="0.6"/>

    </LinearLayout>

</ScrollView>
vrbsm
  • 1,188
  • 15
  • 22
  • Pay attention to the tag android:weightSum = "1" of its linear layout. With layout_weight you can specify a size ratio between multiple views. To get it work you also have to set the height or width (depending on your orientation) to 0px. For more information http://stackoverflow.com/questions/3995825/what-does-androidlayout-weight-mean – vrbsm Aug 11 '15 at 12:28