动画在Activity中不起作用

时间:2016-01-02 09:00:55

标签: android android-layout android-animation

我在一个活动中有4个布局,布局正常。我想当我检查复选框然后隐藏第3个布局和第4个布局向上滑动并替换第3个布局,当取消选中复选框时,第3个布局可见第4个向下滑动并设置正确的位置。

  

但它无法正常工作......

mycode的

 checklayout =(RelativeLayout)findViewById(R.id.layout_check);
    promolayout =(RelativeLayout)findViewById(R.id.promo_layout);
    _Payment_full=(RelativeLayout)findViewById(R.id.pay_full);
        _CheckBox = (CheckBox) findViewById(R.id.check_wallet);
        _CheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) {
                if (isChecked == true) {
                    promolayout.setVisibility(View.GONE);
                    _Payment_full.startAnimation(slide_up);
                    _Payment_full.animate()
                            .translationYBy(100)
                            .translationY(0)
                            .setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
                    String url = "http://www.example.com/index.php";
                    StringRequest postRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {

                                    try {

                                        JSONObject json_Response = new JSONObject(response);
                                        String _RchAmount = json_Response.getString("pay_from_wallet");
                                        String _Remainbalance = json_Response.getString("ewalletbalance");
                                        String _InrPay = json_Response.getString("amt_collected");
                                        confirm_payWallet.setText("Pay from Yup Wallet Rs. " + _RchAmount);
                                        confirm_TotalWallet.setText("Your current wallet balance is Rs." + _Remainbalance);
                                        total_pay.setText("Rs. " + _InrPay);
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                    Log.d("checked in wallet", "------>" + response);
                                }
                            },
                            new Response.ErrorListener() {
                                public void onErrorResponse(VolleyError error) {
                                    Log.e("Checked err error==", "===>" + error);
                                    error.printStackTrace();
                                }
                            }) {

                        protected Map<String, String> getParams() {
                            MyApplication uid = (MyApplication) getApplicationContext();
                            String user = uid.getuser();
                            MyApplication _tansId = (MyApplication) getApplicationContext();
                            String trans_id = _tansId.getTransaction();
                            Map<String, String> params = new HashMap<>();
                            params.put("akey", "XXXXXX");
                            params.put("userid", user);
                            params.put("transid", trans_id);
                            params.put("ewallet_checkbox", "on");

                            Log.i(TAG, "Sending Value" + params);
                            return params;
                        }
                    };
                    newApp.getInstance().addToRequestQueue(postRequest);
                  }
                else
                 {
                    promolayout.setVisibility(View.VISIBLE);
                    _Payment_full.startAnimation(slide_down);
                     _Payment_full.animate()
                         .translationYBy(0)
                         .translationY(100)
                         .setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
                    String url = "http://www.example.com/index.php";
                    StringRequest postRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {

                                    try {

                                        JSONObject json_Response = new JSONObject(response);
                                        String _RchAmount = json_Response.getString("pay_from_wallet");
                                        String _Remainbalance = json_Response.getString("ewalletbalance");
                                        String _InrPay = json_Response.getString("amt_collected");
                                        confirm_payWallet.setText("Pay from Yup Wallet Rs. " + _RchAmount);
                                        confirm_TotalWallet.setText("Your current wallet balance is Rs." + _Remainbalance);
                                        total_pay.setText("Rs. " + _InrPay);
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                    Log.d("checked in wallet", "------>" + response);
                                }
                            },
                            new Response.ErrorListener() {
                                public void onErrorResponse(VolleyError error) {
                                    Log.e("Checked err error==", "===>" + error);
                                    error.printStackTrace();
                                }
                            }) {

                        protected Map<String, String> getParams() {
                            MyApplication uid = (MyApplication) getApplicationContext();
                            String user = uid.getuser();
                            MyApplication _tansId = (MyApplication) getApplicationContext();
                            String trans_id = _tansId.getTransaction();
                            Map<String, String> params = new HashMap<>();
                            params.put("akey", "XXXXXX");
                            params.put("userid", user);
                            params.put("transid", trans_id);
                            params.put("ewallet_checkbox", "off");

                            Log.i(TAG, "Sending Value" + params);
                            return params;
                        }
                    };
                    newApp.getInstance().addToRequestQueue(postRequest);
                }
            }
        });

1 个答案:

答案 0 :(得分:-2)

_Payment_full.animate()
             .translationYBy(100)
             .translationY(0)
             .setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)).start();