Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I figured out a solution to this that should be easy to implement. It involves modifying the layout and the Activity inflating the layout... see below: </p> <p>Activity (QuickPlay.java):</p> <pre><code>public class QuickPlay extends Activity implements AnimationListener { private ImageView myImageView; private LinearLayout LL; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.quick_play_screen); myImageView = (ImageView) this.findViewById(R.id.Clip); LL = (LinearLayout) this.findViewById(R.id.QuickPlayClipLayout); //finally Animation anim = AnimationUtils.loadAnimation(this, R.anim.slide_in_quickplay); anim.setAnimationListener(this); LL.startAnimation(anim); } @Override public void onAnimationEnd(Animation animation){} @Override public void onAnimationRepeat(Animation animation){} @Override public void onAnimationStart(Animation animation) { // This is the key... //set the coordinates for the bounds (left, top, right, bottom) based on the offset value (50px) in a resource XML LL.layout(0, -(int)this.getResources().getDimension(R.dimen.quickplay_offset), LL.getWidth(), LL.getHeight() + (int)this.getResources().getDimension(R.dimen.quickplay_offset)); } } </code></pre> <p>New LinearLayout (CustomLinearLayout.java):</p> <pre><code>public class CustomLinearLayout extends LinearLayout { private Context myContext; public CustomLinearLayout(Context context, AttributeSet attrs) { super(context, attrs); myContext = context; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec+((int)myContext.getResources().getDimension(R.dimen.quickplay_offset))); } } </code></pre> <p>Layout (/res/layout/quick_play_screen.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;com.games.mygame.CustomLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/QuickPlayClipLayout"&gt; &lt;ImageView android:id="@+id/Clip" android:background="@drawable/clip" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;/ImageView&gt; &lt;/com.games.mygame.CustomLinearLayout&gt; </code></pre> <p>Resource (/res/values/constants.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;dimen name="quickplay_offset"&gt;50dp&lt;/dimen&gt; &lt;/resources&gt; </code></pre> <p>Animation (/res/anim/slide_in_quickplay.xml):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;set xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="1000"/&gt; &lt;alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000" /&gt; &lt;/set&gt; </code></pre> <p>The program now does exactly what I need it to do. The entire layout starts off screen at the bottom, slides in in 1 sec and comes to a rest where the top of the layout is actually 50px off the top of the screen (i.e. <code>LL.getTop() = -50</code>) and the bottom of the layout is resting at the bottom of the screen (i.e. <code>LL.getBottom() = 530 = 480 + 50</code>).</p>
 

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