我按照我的设计将屏幕分成2个,顶部填充了Top Fragment,底部填充了Bottom Fragment。初始对齐工作正常。
但我有一系列顶部碎片必须从右向左滑动,每次延迟0.5秒。此外,当第一个片段在完成向左滑动之前滑入(可能是剩下25%以完成左侧滑动)时,第二个幻灯片必须从右侧开始。
所有这些都需要立即发生。
所以,我编写了下面的代码,但只有最后一个片段插入,其余片段没有。请让我知道如何更正此代码。
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class SampleActivity extends Activity {
private void incarnate(FragmentManager fm){
int layoutId = R.id.frame;
boolean fragmentWasNull = false;
Fragment f = fm.findFragmentById(layoutId);
FragmentTransaction ft = fm.beginTransaction();
ft.add(layoutId, new ClinicloudGreyFragment(), "main").commit();
FragmentTransaction ft1 = fm.beginTransaction();
ft1.add(R.id.bottomPanel,new ClinicloudBottonFragment());
ft1.commit();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
FragmentManager fm = getFragmentManager();
incarnate(fm);
FragmentTransaction transaction = fm.beginTransaction();
transaction.setCustomAnimations(R.anim.slidein, R.anim.slideout);
transaction.replace(R.id.frame, new ClinicloudGreyFragment()).commit();
FragmentTransaction transaction1 = fm.beginTransaction();
transaction1.setCustomAnimations(R.anim.slideinwithhalfasecdelay, R.anim.slideout);
transaction1.replace(R.id.frame, new ClinicloudPurpleFragment()).commit();
FragmentTransaction transaction2 = fm.beginTransaction();
transaction2.setCustomAnimations(R.anim.slideinwithasecdelay, R.anim.slideout);
transaction2.replace(R.id.frame, new ClinicloudOrangeFragment()).commit();
FragmentTransaction transaction3 = fm.beginTransaction();
transaction3.setCustomAnimations(R.anim.slideinwithoneandhalfasecdelay, R.anim.slideout);
transaction3.replace(R.id.frame, new ClinicloudYellowFragment()).commit();
FragmentTransaction transaction4 = fm.beginTransaction();
transaction4.setCustomAnimations(R.anim.slideinwithtwosecdelay, R.anim.slideout);
transaction4.replace(R.id.frame, new ClinicloudBlueFragment()).commit();
}
}
Sliding in and sliding out (I dont want sliding out ONLY sliding in to the left from right)
Sliding in
==========
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="1"
android:valueTo="0"
android:valueType="floatType"
android:propertyName="XFraction"
android:startOffset="1000"
/>
<objectAnimator
android:valueFrom="1.0" android:valueTo="0.0"
android:valueType="floatType"
android:propertyName="alpha"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
Sliding out
===========
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="0"
android:valueTo="0"
android:valueType="floatType"
android:propertyName="translationX"
android:duration="@android:integer/config_mediumAnimTime" />
<objectAnimator
android:valueFrom="0.0"
android:valueTo="0.0"
android:valueType="floatType"
android:propertyName="alpha"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
Fragment Example:
-----------------
<?xml version="1.0" encoding="utf-8"?>
<com.clinicloud.app.LL xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#1893D2"
>
</com.clinicloud.app.LL>
public class LL extends LinearLayout {
public LL(Context context) {
super(context);
}
public LL(Context context, AttributeSet attrs) {
super(context, attrs);
}
public float getXFraction() {
final int width = getWidth();
if (width != 0) return getX() / getWidth();
else return getX();
}
public void setXFraction(float xFraction) {
final int width = getWidth();
float newWidth = (width > 0) ? (xFraction * width) : -9999;
setX(newWidth);
}
}
我按照此帖子的最后一个答案Can't get objectAnimator working with xFraction