我在交易期间做片段动画,但我只能做左滑。右滑动画不会影响任何东西。请帮助:我已经尝试了所有方法并搜索了 google 和其他 stackoverflow 问题,并做了他们建议的所有事情。动画中的右滑仍然没有做任何事情。
以下是片段活动:
public class MainActivity extends FragmentActivity {
static FragmentManager manager;
String arr1[] = { "One", "Two", "Three", "Four", "Five", "Six", "Seven" };
String arr2[] = { "One2", "Two2", "Three2", "Four2", "Five2", "Six2",
"Seven2" };
String arr3[] = { "One23", "Two23", "Three23", "Four23", "Five23", "Six23",
"Seven23" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
manager = getSupportFragmentManager();
StartTransaction(arr1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public static void StartTransaction(String arr[]) {
FragmentOne one = new FragmentOne();
Bundle b = new Bundle();
b.putStringArray("array", arr);
one.setArguments(b);
FragmentTransaction transaction = manager.beginTransaction();
// PROblem is here
transaction.setCustomAnimations(R.anim.slide_right, R.anim.slide_left);// ,R.anim.slide_right,R.anim.slide_left);
transaction.replace(R.id.container, one);
// transaction.addToBackStack(null);
transaction.commit();
}
private void MoveOneLevelUp() {
FragmentOne one = new FragmentOne();
Bundle b = new Bundle();
b.putInt("moveup", 1);
one.setArguments(b);
FragmentTransaction transaction = manager.beginTransaction();
transaction.setCustomAnimations(R.anim.slide_left, R.anim.slide_right,
R.anim.slide_right, R.anim.slide_left);
transaction.replace(R.id.container, one);
transaction.addToBackStack(null);
transaction.commit();
}
}
这是片段代码:
public class FragmentOne extends Fragment implements OnItemClickListener {
Activity activity;
ListView list;
View v;
String arr1[] = {"One","Two","Three","Four","Five","Six","Seven"};
String arr2[] = { "One2", "Two2", "Three2", "Four2", "Five2", "Six2",
"Seven2" };
String arr3[] = { "One23", "Two23", "Three23", "Four23", "Five23", "Six23",
"Seven23" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
activity = getActivity();
String array[] = getArguments().getStringArray("array");
v = LayoutInflater.from(activity).inflate(R.layout.first_view, null);
list = (ListView)v.findViewById(R.id.listview);
list.setOnItemClickListener(this);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, array);
list.setAdapter(adapter);
return v;
// return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
if(position ==2) {
MainActivity.StartTransaction(arr2);
} else {
MainActivity.StartTransaction(arr3);
}
}
}
向左滑动动画 xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="700"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
</set>
向右滑动 xml:
<?xml version="1.0" encoding="utf-8"?>`enter code here`
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="700"
android:fromXDelta="0%"
android:toXDelta="100%" >
</translate>
</set>