Android:相对布局儿童无法点击

时间:2014-09-08 07:23:20

标签: android android-layout

我的问题是我有一个相对布局,在另一个相对布局中有两个按钮,我设置动画,使其从页面底部向上滑动,覆盖约一半的父布局。

这是我的xml文件:

<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>

这是活动

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

    });

}

弹出的两个按钮实际上都不可点击(onClick听众正在工作),当我尝试点击&#34;不完整的&#34;按钮例如,它只是从&#34;更新&#34;再次执行动画。按钮。 我想如果你自然地把一个相对的布局放在另一个面前,孩子们也会来到前面。我真的在这个简单的事情上挣扎。

1 个答案:

答案 0 :(得分:-2)

试过这个并且它有效。什么不适合你???试试这个,让我知道它是否适合你?然后我们就能解决您的问题

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

    });

}
}