a

Creating an Android Image Slider Control for your App (Part 1 of 3)

Would you like to create an Android Image Slider Control for your App?At Allcode, we needed to build an Image Slider Control into one of our client’s Android apps. Initially, we thought it would be as simple as implementing the standard Android Gallery Widget,http://developer.android.com/reference/android/widget/Gallery.html Unfortunately, the Gallery Control has been deprecated, which means that it […]

Would you like to create an Android Image Slider Control for your App?
At Allcode, we needed to build an Image Slider Control into one of our client’s Android apps. Initially, we thought it would be as simple as implementing the standard Android Gallery Widget,
http://developer.android.com/reference/android/widget/Gallery.html

Unfortunately, the Gallery Control has been deprecated, which means that it won’t work on new devices.
After digging around a little bit more, we found that most of the implementations were based upon the the ViewPager,
http://developer.android.com/reference/android/support/v4/view/ViewPager.html

The ViewPager has problems as well. First, it’s not supported on old devices. Second, since the the ViewPager is new, it stated that “”Note this class is currently under early design and development. The API will likely change in later updates of the compatibility library, requiring changes to the source code of apps when they are compiled against the newer version.” Yuck.


So at Allcode, we built our own Image Slider based upon the HorizontalScrollView. The first part was easy. We just created a HorizontalScrollView to hold a Horizontal Linear Layout with the slider items. The Option class is just a bean that has a name and a URL. The DownloadImageTask is an asynchronous task that will handle loading and caching the images on an ImageView.

public class ImageSlider extends HorizontalScrollView {
	private List images = new LinkedList();
	private LinearLayout layout;
	private int currentSelectedIndex = 0;
	public ImageSlider(Context context) {
		super(context);
		init(context);
	}
	public ImageSlider(Context context, List images) {
		super(context);
		this.images = images;
		init(context);
	}
	void init(Context context) {
		setHorizontalFadingEdgeEnabled(false);
		setVerticalFadingEdgeEnabled(false);
		layout = new LinearLayout(context);
		LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		layout.setLayoutParams(lParams);
		this.addView(layout);
		for(Option image: images){
			View sliderItem = ((Activity)context).getLayoutInflater().inflate(R.layout.slider_item, layout, false);
			ImageView tmpImage = (ImageView)sliderItem.findViewById(R.id.sliderImage);
			tmpImage.setContentDescription(image.getName());
			TextView tmpText = (TextView)sliderItem.findViewById(R.id.sliderText);
			tmpText.setText(image.getName());
			DownloadImageTask imageTask = new DownloadImageTask(tmpImage);
			imageTask.execute(image.getValue());
			layout.addView(sliderItem);
		}
	}
}

We also created the layout for each of the slider items as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/sliderImage"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:adjustViewBounds="true"
        android:scaleType="centerInside"
        android:padding="5dp"
        />
    <TextView
        android:id="@+id/sliderText"
        android:layout_width="wrap_content"
    	android:layout_height="wrap_content"
    	android:layout_gravity="center_horizontal"
        />
</LinearLayout>

Our next post will detail some of the issues that we had in adding this ImageSlider to a view.

Joel Garcia
Joel Garcia

Joel Garcia has been building AllCode since 2015. He’s an innovative, hands-on executive with a proven record of designing, developing, and operating Software-as-a-Service (SaaS), mobile, and desktop solutions. Joel has expertise in HealthTech, VoIP, and cloud-based solutions. Joel has experience scaling multiple start-ups for successful exits to IMS Health and Golden Gate Capital, as well as working at mature, industry-leading software companies. He’s held executive engineering positions in San Francisco at TidalWave, LittleCast, Self Health Network, LiveVox acquired by Golden Gate Capital, and Med-Vantage acquired by IMS Health.

Related Articles

The Difference Between Amazon RDS and Aurora

The Difference Between Amazon RDS and Aurora

AWS does incorporate several database services that offer high performance and great functionality. However, customers do find the difference between Amazon Relational Database Service and Amazon Aurora. Both services do provide similar functions, but do cover their own use cases.

AWS Snowflake Data Warehouse Pricing Guide

AWS Snowflake Data Warehouse Pricing Guide

AWS Snowflake Data Warehouse – or just Snowflake – is a data cloud built for users to mobilize, centralize, and process large quantities of data. Regardless of how many sources are connected to Snowflake or the user’s preferred type of organized data used, data is easily stored and controllably shared with selectively-authorized access. Snowflake does offer extensive control over its pricing, though how it works isn’t always clear.

Guide to Cost Factors for Amazon’s RDS Pricing

Guide to Cost Factors for Amazon’s RDS Pricing

Addressing the question of what influences Amazon RDS costs, it’s important to note that Amazon sports a complex pricing model. While the pay-for-what-you-use model seems straightforward, there are nuanced aspects to consider. Factors such as data usage and the choice of computing components can swiftly deplete one’s budget allocation. However, this doesn’t mean that AWS is inherently costly. With proper planning and a deep understanding of the contributing elements to billing, users can navigate and optimize their expenses effectively.

Download our 10-Step Cloud Migration ChecklistYou'll get direct access to our full-length guide on Google Docs. From here, you will be able to make a copy, download the content, and share it with your team.