Running a Startup on AWS? Get Funding With AWS JumpStart. Click Here to Learn More

2021 Fillmore Street #1128

}

24/7 solutions

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

Here’s Why You Should Work with an AWS Partner

Here’s Why You Should Work with an AWS Partner

Amazon Web Services is understandably a difficult platform to adapt to and utilize fully upon first getting started. Some organizations can be selected to become certified partners to indirectly extend services to help build on the Amazon Cloud. Finding a certified company to help build out is undoubtedly the best way to significantly simplify, streamline, and reduce the cost of utilizing AWS.

Amazon Web Services – CodeCatalyst

Amazon Web Services – CodeCatalyst

When a development team is building out an application, it helps to have access to the same resources, have the tools for planning and testing, and to have access to the application all in one place. CodeCatalyst comes with a slew of continuous integration/continuous development (CI/CD) tools and can leverage other AWS services and be connected to other AWS projects on an account. As a collaborative tool, it is easy to introduce new members into the project and to log all activity or all tests from a single dashboard. It’s a complete package of all the tools needed to securely work on every step of an application’s lifecycle.

The Definitive Guide to AWS Pricing

The Definitive Guide to AWS Pricing

Perhaps the biggest issue with AWS that its competitors edge out on is the confusing pricing model. It does promise the capacity to help users save significantly on funds that otherwise by avoiding spending on unnecessary resources, but getting to that point isn’t always clear. We will be covering in greater detail how this works.

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.