布局
`<FrameLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_45" >
<Button
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_45"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:background="@drawable/btn_red"
android:onClick="onClick"
android:text="登錄"
android:textColor="@color/white"
android:textSize="@dimen/sp_17"
android:visibility="visible"/>
<LinearLayout
android:id="@+id/login_loading_ll"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_45"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:background="@drawable/btn_red"
android:gravity="center"
android:visibility="gone" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="登錄中"
android:textColor="@color/white"
android:textSize="@dimen/sp_17" />
<ImageView
android:id="@+id/login_loading"
android:layout_width="@dimen/dp_20"
android:layout_height="@dimen/dp_20"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_5"
android:contentDescription="@null"
android:scaleType="centerInside"
android:src="@drawable/icon_new_file" />
</LinearLayout>
</FrameLayout>`
然后代碼中
loadingLogin = (LinearLayout) findViewById(R.id.login_loading_ll); loginIv = (ImageView) findViewById(R.id.login_loading); loginIv.setColorFilter(Color.WHITE);
動(dòng)畫
Animation operatingAnim = AnimationUtils.loadAnimation(mContext, R.anim.image_rotate);
login_button.setVisibility(View.GONE); loadingLogin.setVisibility(View.VISIBLE); loginIv.startAnimation(operatingAnim);
登錄失敗
login_button.setVisibility(View.VISIBLE); loadingLogin.setVisibility(View.GONE); loginIv.clearAnimation();
R.anim.image_rotate
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="359" android:duration="3000" android:repeatCount="-1" android:pivotX="50%" android:pivotY="50%" /> </set>