Програмен код за приложения на Android

Android custom loader – за зареждане

Статична снимка за зареждане в Андроид (Loader).

Можете да скривате и показвате когато си поискате зареждането. Това става чрез функциите startLoading() и stopLoading().

<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/loaderLayout"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@color/menuBackground"
        android:clickable="true"
        android:visibility="gone" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:contentDescription="@string/loading"
            android:src="@drawable/loader" />

    </RelativeLayout>

</RelativeLayout>
	ImageView loaderImageView;
	View loaderLayout;
	RotateAnimation animation;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		loaderImageView = (ImageView) findViewById(R.id.imageView1);
		loaderImageView.setDrawingCacheEnabled(true);
		loaderImageView.setDrawingCacheQuality(loaderImageView.DRAWING_CACHE_QUALITY_HIGH);
    	animation = new RotateAnimation(0f, 355f,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f);
    	animation .setInterpolator(new LinearInterpolator());
        animation .setRepeatCount(Animation.INFINITE);
        animation .setDuration(2000); 
		loaderLayout = findViewById(R.id.loaderLayout);
		
		startLoading();
		DoSomething();
		stopLoading();
	}
	
    protected void startLoading() {
    	loaderLayout.setVisibility(View.VISIBLE);
        loaderImageView.startAnimation(animation);
    }
 
    protected void stoptLoading() {
    	loaderLayout.setVisibility(View.GONE);
        // Later.. stop the animation
        loaderImageView.setAnimation(null);
    }
    protected void doSomething() {
        //TODO something
    };

Няма коментари

  • Страница 2 от 2
  • <
  • 1
  • 2
  1. Няма коментари.
(will not be published)