Add/Set shadow effect on listview items in android

How to create list view with awesome shadow effects on each text value item of listview like Photoshop text effect.

In this tutorial we are creating list view with item shadow effect to give 3-D effect on listview items using setShadowLayer() method. So here is the complete step by step tutorial for Add/Set shadow effect on listview items in android.

android-project-download-code-button

How to Add/Set shadow effect on listview items in android.

Code for MainActivity.java file.

 package com.setshadoweffect_android_examples.com;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
 ListView listView;
 String[] listValue = new String[] 
 {
 "ONE",
 "TWO",
 "THREE",
 "FOUR",
 "FIVE",
 "SIX"
 };
 
 List<String> LISTSTRING;
 @Override
 protected void onCreate(Bundle savedInstanceState) 
 {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 listView = (ListView)findViewById(R.id.listView1);
 
 LISTSTRING = new ArrayList<String>(Arrays.asList(listValue));
 
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_2, android.R.id.text1, LISTSTRING){
 
 @Override
 public View getView(int position, View convertView, ViewGroup parent){
 
 View view = super.getView(position, convertView, parent);

 TextView textview =(TextView) view.findViewById(android.R.id.text1);
 
 //Setting up shadow effect.
 textview.setShadowLayer(1.3f, 4.0f, 4.0f, Color.parseColor("#fdab52"));

 return view;
 
 }
 };
 
 listView.setAdapter(adapter); 
 
 }
 }

Code for activity_main.xml layout file.

 <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.setshadoweffect_android_examples.com.MainActivity" >

 <ListView
 android:id="@+id/listView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true" >
 </ListView>

</RelativeLayout>

Screenshot:

Add/Set shadow effect on listview items in android

Click here to download Add/Set shadow effect on listview items in android project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *