Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views5 pages

Document

The document outlines the creation of an Android application featuring a horizontal scroll view that displays images. It includes XML layout code for the main activity, instructions for adding images to the drawable folder, and a basic Java class for the main activity. The app allows users to scroll left or right to view additional images.

Uploaded by

harshalns14061
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Document

The document outlines the creation of an Android application featuring a horizontal scroll view that displays images. It includes XML layout code for the main activity, instructions for adding images to the drawable folder, and a basic Java class for the main activity. The app allows users to scroll left or right to view additional images.

Uploaded by

harshalns14061
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. activity_main.

xml

<?xml version=”1.0” encoding=”utf-8”?>

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

Xmlns:tools=http://schemas.android.com/tools

Android:layout_width=”match_parent”

Android:layout_height=”match_parent”

Android:orientation=”vertical”

Tools:context=”.MainActivity”>

<TextView

Android:layout_width=”match_parent”

Android:layout_height=”wrap_content”

Android:text=”Horizontal Scroll View Example”

Android:textSize=”20sp”

Android:textStyle=”bold”

Android:gravity=”center”

Android:padding=”10dp”/>

<HorizontalScrollView

Android:layout_width=”match_parent”

Android:layout_height=”wrap_content”
Android:fillViewport=”true”

Android:scrollbars=”none”>

<LinearLayout

Android:layout_width=”wrap_content”

Android:layout_height=”wrap_content”

Android:orientation=”horizontal”

Android:padding=”10dp”>

<ImageView

Android:layout_width=”150dp”

Android:layout_height=”150dp”

Android:src=”@drawable/image1”

Android:layout_marginEnd=”10dp”/>

<ImageView

Android:layout_width=”150dp”

Android:layout_height=”150dp”

Android:src=”@drawable/image2”

Android:layout_marginEnd=”10dp”/>

<ImageView

Android:layout_width=”150dp”

Android:layout_height=”150dp”

Android:src=”@drawable/image3”

Android:layout_marginEnd=”10dp”/>
<ImageView

Android:layout_width=”150dp”

Android:layout_height=”150dp”

Android:src=”@drawable/image4”

Android:layout_marginEnd=”10dp”/>

</LinearLayout>

</HorizontalScrollView>

</LinearLayout>

2. Add Images in Drawable Folder

Add sample images to res/drawable/ with names like image1.png,


image2.png, image3.png, image4.png.

If you don’t have images, use Android Studio’s built-in vector assets.

3. MainActivity.java
Package com.example.horizontalscrollviewapp;

Import androidx.appcompat.app.AppCompatActivity;

Import android.os.Bundle;

Public class MainActivity extends AppCompatActivity {

@Override

Protected void onCreate(Bundle savedInstanceState) {

Super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

4. Run the App

This app will display images in a horizontal scroll view.

You can scroll left or right to view more images.

You might also like