Note that there are some explanatory texts on larger screens.

plurals
  1. POstartAnimation() is not being called
    primarykey
    data
    text
    <p>I am trying to implement the Youtube style sliding menu with two fragments. I have created a custom animation that will change the width of the left fragment with the toggle function is called on pressing the app icon on the Action bar. The Expand.java will increase the width while Collapse.java will decrease the width. When i call the startAnimation() function from the onCreate() of the MainActivity.java, it works fine. But when i call it from withing the toggle(), it doesnt work, though the constructor of Expand.java and Collapse.java are </p> <p>activity_main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" &gt; &lt;LinearLayout android:id="@+id/f1" android:layout_height="match_parent" android:layout_width="0dip" &gt; &lt;fragment android:id="@+id/listFragment" android:layout_height="match_parent" android:layout_width="match_parent" class="com.surv.ui123.FragLeft" &gt; &lt;/fragment&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/f2" android:layout_height="match_parent" android:layout_width="match_parent" &gt; &lt;fragment android:id="@+id/detailFragment" android:layout_width="match_parent" android:layout_height="match_parent" class="com.surv.ui123.FragRight" &gt; &lt;/fragment&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>FragLeft.java</p> <pre><code>package com.surv.ui123; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class FragLeft extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragleft, container, false); return view; } } </code></pre> <p>FragRight.java</p> <pre><code>package com.surv.ui123; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class FragRight extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragright, container, false); return view; } } </code></pre> <p>Expand.java</p> <pre><code>package com.surv.ui123; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.widget.Toast; public class Expand extends Animation implements Animation.AnimationListener { private View view; private static long ANIMATION_DURATION; private int FromWidth; private int ToWidth; public Expand(View v, int FromWidth, int ToWidth) { this.view = v; ANIMATION_DURATION = 1; this.FromWidth = FromWidth; this.ToWidth = ToWidth; setDuration(ANIMATION_DURATION); setRepeatCount(10); setFillAfter(false); setInterpolator(new AccelerateInterpolator()); Toast.makeText(view.getContext(),"Expand",Toast.LENGTH_SHORT).show(); setAnimationListener(this); } @Override public void onAnimationEnd(Animation arg0) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub LayoutParams lyp = view.getLayoutParams(); lyp.width = lyp.width+(int)(ToWidth/10); view.setLayoutParams(lyp); } @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub Toast.makeText(view.getContext(),"Strarted Expand",Toast.LENGTH_SHORT).show(); } } </code></pre> <p>Collapse.java</p> <pre><code>package com.surv.ui123; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.widget.Toast; public class Collapse extends Animation implements Animation.AnimationListener { private View view; private static long ANIMATION_DURATION; private int FromWidth; private int ToWidth; public Collapse(View v, int ToWidth, int FromWidth) { Toast.makeText(view.getContext(),"Collapse",Toast.LENGTH_SHORT).show(); this.view = v; ANIMATION_DURATION = 1; this.FromWidth = FromWidth; this.ToWidth = ToWidth; setDuration(ANIMATION_DURATION); setRepeatCount(10); setFillAfter(false); setInterpolator(new AccelerateInterpolator()); setAnimationListener(this); } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { LayoutParams lyp = view.getLayoutParams(); lyp.width = lyp.width-(int)(ToWidth/10); view.setLayoutParams(lyp); } @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } } </code></pre> <p>MainActivity.java</p> <pre><code>package com.surv.ui123; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.ViewGroup.LayoutParams; import android.widget.LinearLayout; import com.actionbarsherlock.app.SherlockFragmentActivity; public class MainActivity extends SherlockFragmentActivity { LinearLayout MenuList,RFrg; boolean isExpanded=true; int screenWidth; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MenuList = (LinearLayout) findViewById(R.id.f1); RFrg=(LinearLayout) findViewById(R.id.f2); LayoutParams lyp = RFrg.getLayoutParams(); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); screenWidth = metrics.widthPixels; lyp.width = screenWidth; RFrg.setLayoutParams(lyp); getSupportActionBar().setHomeButtonEnabled(true); } @Override public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // app icon in action bar clicked; go home toggle(); return true; default: return super.onOptionsItemSelected(item); } } public void toggle() { isExpanded=!isExpanded; if (isExpanded) { Collapse x= new Collapse(MenuList, 0,(int)(screenWidth*0.75)); MenuList.startAnimation(x); }else { Expand d=new Expand(MenuList, 0,(int)(screenWidth*0.75)); MenuList.startAnimation(d); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload