在我的MainActivity's xml
文件中,activity_main.xml
我有一个显示预订列表的FrameLayout
:
<ProgressBar android:id="@+id/login_progress" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginTop="16dp"
android:visibility="gone"
android:layout_gravity="center"/>
<FrameLayout android:id="@+id/home_page_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
当用户想通过点击消除一个预约时,必须更新列表,因此我使用这种方法对网络进行呼叫:
public void cancelReservation(ReservationResponse rR){
if (mNetwork != null) {return;}
if (isNetworkAvailable()) {
showProgress(true);
mNetwork = new NetworkTask(this, "cancel_reservation", rR);
mNetwork.execute((Void) null);
}else{
// display error
Log.d("LOG_TAG", "No network available!");
Toast.makeText(this, R.string.no_network_dialog ,Toast.LENGTH_LONG).show();
}
}
更新AppEngine
个预订,并将更新的列表返回Activity
。
在执行AsyncTask
之前,我调用方法showProgress
,开始这个简单的动画:
该方法具有恒定的持续时间,在此期间隐藏FrameLayout
以支持ProgressBar
;然后在ProgressBar
onAnimationEnd
方法中恢复FrameLayout
并将动画设置为View.GONE
,最后显示更新的预订列表:
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void showProgress(final boolean showProgr) {
final FrameLayout home_scroll = (FrameLayout) findViewById(R.id.home_page_frame);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
mProgressView.destroyDrawingCache();
int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
home_scroll.setVisibility(showProgr ? View.GONE : View.VISIBLE);
mProgressView.setVisibility(showProgr ? View.VISIBLE : View.GONE);
mProgressView.animate().setDuration(shortAnimTime*9).alpha(
showProgr ? 0 : 1).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mProgressView.setVisibility(showProgr ? View.GONE : View.VISIBLE);
home_scroll.setVisibility(showProgr ? View.VISIBLE : View.GONE);
}
});
} else {
home_scroll.setVisibility(showProgr ? View.GONE : View.VISIBLE);
}
}
我古怪的问题是,当我第一次取消预约时,会显示动画,从第二次开始,每次取消预约时动画都不会出现。怎么样?
我已尝试过调用此方法:
mProgressView.destroyDrawingCache();
但它没有用......
答案 0 :(得分:0)
我通过修改我使用方法@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void showProgress(final boolean showProgr) {
// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
// for very easy animations. If available, use these APIs to fade-in
// the progress spinner.
final FrameLayout home_scroll = (FrameLayout) findViewById(R.id.home_page_frame);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
mProgressView.refreshDrawableState();//setVisibility(View.GONE);
if(showProgr) {
home_scroll.setVisibility(showProgr ? View.GONE : View.VISIBLE);
mProgressView.setVisibility(showProgr ? View.VISIBLE : View.GONE);
mProgressView.animate();
}else{
mProgressView.setVisibility(showProgr ? View.VISIBLE : View.GONE);
mProgressView.invalidate();
mProgressView.clearAnimation();
mProgressView.setActivated(false);
home_scroll.setVisibility(showProgr ? View.GONE : View.VISIBLE);
}
} else { //TODO debug <= HONEYCOMB
home_scroll.setVisibility(showProgr ? View.GONE : View.VISIBLE);
}
}
的方式解决了这个问题。
showProgress
在我使用该方法之前,通过设置一个简短的动画并等待它自己完成。 Insead,通过不设置计时器并调用showProgress(true)
方法两次,首先是动画必须以showProgress(false)
开头,第二次是当它必须以 $serverName = "xxxx\SQLEXPRESS"; //serverName\instanceName
$connectionInfo = array( "Database"=>"xxxx", "UID"=>"xxx", "PWD"=>"xxxx" , "CharacterSet" => "UTF-8");
$con = sqlsrv_connect( $serverName, $connectionInfo);
if($con) {
echo "Connection established";
}
else{
echo "Connection could not be established.";
die( print_r( sqlsrv_errors(), true));
}
$query = "SET IDENTITY_INSERT dbo.xxx ON ";
$query = "INSERT INTO dbo.xxx([Id],[IdFirma], [VrstaDokumenta], [BrojDokumenta], [BrojDokumentaKroz],
[DatumDokumenta], [IdKupac], [VrstaCijene], [IdKorisnik], [NacinPlacanja], [DatumZadnjeAkcije], [Status], [StatusArhive],
[StatusIzmjene],
[StatusStampe], [VrstaFakture])
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$params = array($id,$IdFirma,$VrstaDokumenta,$BrojDokumenta, $BrojDokumentaKroz, $DatumDokumenta, $IdKupac, $VrstaCijene, $IdKorisnik,
$NacinPlacanja, $DatumZadnjeAkcije, $Status, $StatusArhive, $StatusIzmjene, $StatusStampe, $VrstaFakture);
/* Prepare and execute the statement. */
$stmt = sqlsrv_query( $con, $query, $params);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
结束时,然后全部很好地工作。