Hello Friends I have just started learning android by watch videos by Travis.
He has made and app having an Image slider in it. I followed each and every step and everything is working fine. He has used
Below is my XML code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/IVDisplay"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="@drawable/a"
/>
<Button
android:id="@+id/setBG"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/set_as_wallpaper" />
<HorizontalScrollView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fillViewport="true"
android:scrollbars="horizontal|vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/viewImage1"
android:layout_width="125dp"
android:layout_height="125dp"
android:padding="15dp"
android:src="@drawable/a" />
<ImageView
android:id="@+id/viewImage2"
android:layout_width="125dp"
android:layout_height="125dp"
android:padding="15dp"
android:src="@drawable/c" />
<ImageView
android:id="@+id/viewImage3"
android:layout_width="125dp"
android:layout_height="125dp"
android:padding="15dp"
android:src="@drawable/d" />
<ImageView
android:id="@+id/viewImage4"
android:layout_width="125dp"
android:layout_height="125dp"
android:padding="15dp"
android:src="@drawable/e" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
Images are displaying right…but at a time there can be only 1 and a half image can be displayed…while there are many other images …so there I am using HorizontalScrollView to show a slider to slide the images.
This is the video which I referred http://www.youtube.com/watch?v=wp5sORsPopw
You have set horizontal scrollview width
android:layout_width="200dp"So to solve you problem replace it toandroid:layout_width="wrap_content".Like this : –
To show the scrollbar in horizontal scrollview.
Write this in layout file where you define horizontal scrollview.
As you are saying I don’t think there is any problem in it. Its working fine. I have checked in emulator. Images are sliding horizontally fine!!