Skip to content

Instantly share code, notes, and snippets.

@peitek peitek/EatFoodyLoadingView Secret
Last active Jun 14, 2019

Embed
What would you like to do?
Custom Loading View Android
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/custom_eat_foody_loading_view_one"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="5dp" />
<ImageView
android:id="@+id/custom_eat_foody_loading_view_two"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="5dp" />
<ImageView
android:id="@+id/custom_eat_foody_loading_view_three"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="5dp" />
<ImageView
android:id="@+id/custom_eat_foody_loading_view_four"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="5dp" />
<ImageView
android:id="@+id/custom_eat_foody_loading_view_five"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="5dp" />
</LinearLayout>
package com.futurestudio.foody.views;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.futurestudio.foody.R;
/**
* Created by future studio/peitek on 8/20/2014.
*/
public class EatFoodyLoadingView extends LinearLayout {
private Handler mHandler;
ImageView first;
ImageView two;
ImageView three;
ImageView four;
ImageView five;
int loadPosition = 0;
public EatFoodyLoadingView(Context context) {
super(context);
}
public EatFoodyLoadingView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.custom_eat_foody_loading_view, this);
first = (ImageView) findViewById(R.id.custom_eat_foody_loading_view_one);
two = (ImageView) findViewById(R.id.custom_eat_foody_loading_view_two);
three = (ImageView) findViewById(R.id.custom_eat_foody_loading_view_three);
four = (ImageView) findViewById(R.id.custom_eat_foody_loading_view_four);
five = (ImageView) findViewById(R.id.custom_eat_foody_loading_view_five);
mHandler = new Handler();
mStatusChecker.run();
}
Runnable mStatusChecker = new Runnable() {
@Override
public void run() {
displayLoadingPosition(loadPosition);
loadPosition++;
mHandler.postDelayed(mStatusChecker, 500);
}
};
private void displayLoadingPosition(int loadPosition) {
int emphasizedViewPos = loadPosition % 5;
first.setImageResource(R.drawable.kuehlschrank_light_green);
two.setImageResource(R.drawable.herd_light_green);
three.setImageResource(R.drawable.haube_light_green);
four.setImageResource(R.drawable.schale_light_green);
five.setImageResource(R.drawable.glas_light_green);
switch (emphasizedViewPos) {
case 0:
first.setImageResource(R.drawable.kuehlschrank_green);
break;
case 1:
two.setImageResource(R.drawable.herd_green);
break;
case 2:
three.setImageResource(R.drawable.haube_green);
break;
case 3:
four.setImageResource(R.drawable.schale_green);
break;
case 4:
five.setImageResource(R.drawable.glas_green);
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.