0

My problem is that I have a relative layout with two buttons within another relative layout and I'm animating it so that it slides up from the bottom of the page and covers about half of the parent layout.

Here is my xml file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/master_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/jobview_drawable"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:textAlignment="center"
tools:context=".JobViewActivity" >

<TextView
    android:id="@+id/name_jobview_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Name"
    android:textColor="#FFFFFF"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/address_jobview_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/name_jobview_item"
    android:layout_below="@+id/name_jobview_item"
    android:layout_marginTop="18dp"
    android:text="Address"
    android:textColor="#FFFFFF"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/priority_jobview_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/address_jobview_item"
    android:layout_below="@+id/address_jobview_item"
    android:layout_marginTop="14dp"
    android:text="Priority"
    android:textColor="#FFFFFF"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/notes_jobview_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/priority_jobview_item"
    android:layout_below="@+id/priority_jobview_item"
    android:layout_marginTop="20dp"
    android:text="Notes"
    android:textColor="#FFFFFF"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="250dp" 
    android:id="@+id/status_panel"
    android:visibility="gone"
    android:background="@drawable/jobbutton_drawable">

    <Button
        android:id="@+id/incomplete_button"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="36dp"
        android:background="@drawable/incompletebutton_drawable"
        android:onClick="setIncomplete"
        android:text="Incomplete" />

    <Button
        android:id="@+id/complete_button"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/incomplete_button"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="24dp"
        android:background="@drawable/completebutton_drawable"
        android:onClick="setComplete"
        android:text="Complete" />

</RelativeLayout>


<Button
    android:id="@+id/updatejob_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="28dp"
    android:background="@drawable/jobbutton_drawable"
    android:height="65dp"
    android:text="Update Job"
    android:onClick="selectStatus"
    android:width="140dp" />

</RelativeLayout>

Here is the Activity

package com.example.samsungui;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class JobViewActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_job_view);
    fillView();

}

public void fillView()
{
    Intent intent = getIntent();

    //Fill view
    TextView name = (TextView) findViewById(R.id.name_jobview_item);
    name.setText(intent.getStringExtra("NAME"));

    TextView address = (TextView) findViewById(R.id.address_jobview_item);
    address.setText(intent.getStringExtra("ADDRESS"));

    TextView priority = (TextView) findViewById(R.id.priority_jobview_item);
    priority.setText(intent.getStringExtra("PRIORITY"));

    TextView notes = (TextView) findViewById(R.id.notes_jobview_item);
    notes.setText(intent.getStringExtra("NOTES"));

}


public void selectStatus(View view)
{

    final RelativeLayout statusPanel = (RelativeLayout) findViewById(R.id.status_panel);
    Button updateButton = (Button) findViewById(R.id.updatejob_button);
    Button incompleteButton = (Button) findViewById(R.id.incomplete_button);
    Button completeButton = (Button) findViewById(R.id.complete_button);

    Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_up);

    statusPanel.startAnimation(slideUp);
    statusPanel.bringToFront();
    statusPanel.setVisibility(View.VISIBLE);

    slideUp.setFillAfter(true);

    incompleteButton.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            Toast.makeText(JobViewActivity.this, "it works", Toast.LENGTH_SHORT).show();
            Animation slideDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);
            statusPanel.startAnimation(slideDown);
            v.startAnimation(slideDown);
            statusPanel.setVisibility(View.GONE);   
        }

    });

    completeButton.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            Toast.makeText(JobViewActivity.this, "it works", Toast.LENGTH_SHORT).show();
            Animation slideDown = AnimationUtils.loadAnimation(getApplicationContext(),        R.anim.slide_down);
            statusPanel.startAnimation(slideDown);
            v.startAnimation(slideDown);
            statusPanel.setVisibility(View.GONE);   
        }

    });

}

Both buttons which pop up aren't actually clickable (onClick listeners are working at all) and when I try to click on the "incomplete" button for example, it just does the animation again from the "update" button. I thought if you naturally brought a relative layout in front of another one, the children would also come in front as well. I'm really struggling on this simple thing.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Try to remote the onClick property of the buttons from the xml layout – Ispas Claudiu Sep 08 '14 at 07:26
  • I've tried that too, still doesnt do anything bro – Chris Szilagyi Sep 08 '14 at 07:26
  • Maybe you should not define your onClickListener inside a function that is called on click. try to define your complete/incomplete buttons outside the function "selectStatus". For ex. define them in "fillView()". It is a better practice – Ispas Claudiu Sep 08 '14 at 07:29
  • You'll need to change the co-ordinates of the `RelativeLayout` after animation completes. Check [Apply changes to View after Animation](http://stackoverflow.com/questions/4397443/how-can-i-apply-the-changes-to-the-position-of-a-view-after-an-animation/7929404#7929404) and [onClick does not translate after Animation](http://stackoverflow.com/questions/11339830/linearlayout-onclick-does-not-translate-after-translateanimation). Or if your minimum API is 11 you can use `ObjectAnimator` – Apoorv Sep 08 '14 at 07:29
  • share a screen cap for before and after slide up animation – Olayinka Sep 08 '14 at 07:37
  • As Apoorv said, it has something to do with the position of the button after the animation as they dont translate properly? I tried the link but I dont really understand what happens in it, could someone give me an answer that can be applied to my example? PLEASE GUYS – Chris Szilagyi Sep 08 '14 at 15:17

1 Answers1

-2

Tried this and it works. So what is not working for you??? Try this and let me know if it works for you? And then we will be able to nail your problem

public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    fillView();

}

public void fillView()
{
    Intent intent = getIntent();

    //Fill view
    TextView name = (TextView) findViewById(R.id.name_jobview_item);
    name.setText(intent.getStringExtra("NAME"));

    TextView address = (TextView) findViewById(R.id.address_jobview_item);
    address.setText(intent.getStringExtra("ADDRESS"));

    TextView priority = (TextView) findViewById(R.id.priority_jobview_item);
    priority.setText(intent.getStringExtra("PRIORITY"));

    TextView notes = (TextView) findViewById(R.id.notes_jobview_item);
    notes.setText(intent.getStringExtra("NOTES"));

}


public void selectStatus(View view)
{

    final RelativeLayout statusPanel = (RelativeLayout) findViewById(R.id.status_panel);
    Button updateButton = (Button) findViewById(R.id.updatejob_button);
    Button incompleteButton = (Button) findViewById(R.id.incomplete_button);
    Button completeButton = (Button) findViewById(R.id.complete_button);

//    Animation slideUp = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_up);

//    statusPanel.startAnimation(slideUp);
    statusPanel.bringToFront();
    statusPanel.setVisibility(View.VISIBLE);

//    slideUp.setFillAfter(true);

    incompleteButton.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            Toast.makeText(MainActivity.this, "incompleteButton works", Toast.LENGTH_SHORT).show();
//            Animation slideDown = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);
//            statusPanel.startAnimation(slideDown);
//            v.startAnimation(slideDown);
            statusPanel.setVisibility(View.GONE);   
        }

    });

    completeButton.setOnClickListener(new OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            Toast.makeText(MainActivity.this, "completeButton works", Toast.LENGTH_SHORT).show();
//            Animation slideDown = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_down);
//            statusPanel.startAnimation(slideDown);
//            v.startAnimation(slideDown);
            statusPanel.setVisibility(View.GONE);   
        }

    });

}
}
Martynas
  • 627
  • 2
  • 8
  • 28