2013-07-01 3 views
2

거래 중에 조각 애니메이션을하고 있지만 왼쪽 슬라이드 만 넣을 수 있습니다. 오른쪽 슬라이드 애니메이션은 아무런 영향을 미치지 않습니다. 도와주세요 : 나는 모든 것을 시도하고 구글과 다른 stackoverflow 질문을 검색하고 그들이 제안한 모든 것을했습니다. 애니메이션에서 여전히 오른쪽 슬라이드는 아무 것도하지 않습니다.거래 중 조각 애니메이션 - 작품의 왼쪽 슬라이드 및 오른쪽 슬라이드 만 들어 있지 않음

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); 
     } 
    } 
} 

슬라이드 왼쪽 ANIM의 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> 
여기
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(); 
    } 
} 

이 프래그먼트 코드 : 이하

프래그먼트 활동
+0

아무도 도와주세요! 제발? – user1733684

+0

2.3.x 이상의 장치에서 작업 할 필요가 있었기 때문에이 작업을하는 데 성가신 시간을 보냈습니다. 당신은 바른 길을 가고있었습니다. @dmanargias 대답을 사용하여 작업 솔루션을 찾았습니다. http://stackoverflow.com/questions/4817900/android-fragments-and-animation – ninehundredt

답변

2

조각 트랜잭션이 필요합니다. 이 같은

시도 뭔가 :

if (mLastMenuWeight > mMenuWeight) { 
    transaction.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right); 
} 
else { 
    transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left); 
} 

가 명심 mLastMenuWeight 및 mMenuWeight 내가 사용해야하는 애니메이션을 추적하기 위해 나를 사용됩니다. 이 조건을 다른 것으로 바꿔야합니다.

안드로이드는 왼쪽에서 오른쪽으로 움직이는 애니메이션 만 포함하므로 원본 애니메이션 코드를 사용하여 오른쪽에서 왼쪽으로 정의해야합니다. 이처럼 :

slide_in_right.xml :

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
/* //device/apps/common/res/anim/slide_in_left.xml 
** 
** Copyright 2007, The Android Open Source Project 
** 
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
** 
**  http://www.apache.org/licenses/LICENSE-2.0 
** 
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License. 
*/ 
--> 

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate android:fromXDelta="50%p" android:toXDelta="0" 
      android:duration="@android:integer/config_mediumAnimTime"/> 
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" 
      android:duration="@android:integer/config_mediumAnimTime" /> 
</set> 

slide_out_left.xml :

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
/* //device/apps/common/res/anim/slide_out_right.xml 
** 
** Copyright 2007, The Android Open Source Project 
** 
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
** 
**  http://www.apache.org/licenses/LICENSE-2.0 
** 
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License. 
*/ 
--> 

<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <translate android:fromXDelta="0" android:toXDelta="-50%p" 
      android:duration="@android:integer/config_mediumAnimTime"/> 
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0" 
      android:duration="@android:integer/config_mediumAnimTime" /> 
</set> 

또한, 추가/새보기를 부착하고 분리 이전을 대신 교체 시도 할 수 있습니다. 아마도 그것은 어쨌든 동일한 행동으로 이어질 것입니다 ...

관련 문제