0
Android에서 cardflip 애니메이션에 문제가 있습니다. 나는 그들의 가이드를 따르고 있고 이것을 이해하려고 애쓰는 AnimationsDemo의 일부를 고르려고 노력 중이다. 하지만 XML에서 모든 카드 뒤집기 및 뒤집기를 만들고 XML로 카드 전면 및 후면 레이아웃을 만들었습니다. onCreate에서 단편을 추가하려고하면 오류 메시지가 계속 표시됩니다. 코드가 사용하는 예제 코드처럼 보이므로 오류를 유발하는 것이 무엇인지 모르겠습니다. 아래에 오류 메시지와 jave 코드가 포함되었습니다. 시간 내 줘서 고마워.Android, cardflip 애니메이션, 조각이 표시되지 않습니다.
public class MainActivity extends ActionBarActivity {
/**
* Whether or not we're showing the back of the card (otherwise showing the front).
*/
private boolean mShowingBack = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager()
.beginTransaction()
.add(R.id.container, new CardFrontFragment())
.commit();
}else {
mShowingBack = (getFragmentManager().getBackStackEntryCount() > 0);
}
/**
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
*/
}
private void flipCard() {
if (mShowingBack) {
getFragmentManager().popBackStack();
return;
}
// Flip to the back.
mShowingBack = true;
// Create and commit a new fragment transaction that adds the fragment for the back of
// the card, uses custom animations, and is part of the fragment manager's back stack.
getFragmentManager()
.beginTransaction()
// Replace the default fragment animations with animator resources representing
// rotations when switching to the back of the card, as well as animator
// resources representing rotations when flipping back to the front (e.g. when
// the system Back button is pressed).
.setCustomAnimations(
R.animator.card_flip_right_in, R.animator.card_flip_right_out,
R.animator.card_flip_left_in, R.animator.card_flip_left_out)
// Replace any fragments currently in the container view with a fragment
// representing the next page (indicated by the just-incremented currentPage
// variable).
.replace(R.id.container, new CardBackFragment())
// Add this transaction to the back stack, allowing users to press Back
// to get to the front of the card.
.addToBackStack(null)
// Commit the transaction.
.commit();
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
/**
* A fragment representing the front of the card.
*/
public static class CardFrontFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.card_front, container, false);
}
}
/**
* A fragment representing the back of the card.
*/
public static class CardBackFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.card_back, container, false);
}
}
}
오류 :
The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MainActivity.CardFrontFragment) MainActivity.java /Lab6b/src/you/ca/mohawk/lab6b line 28 Java Problem
예, 작동했습니다. 제안에 감사드립니다. – khmer2040