Android fake Alipay payment from bottom window effect _android

Source: Internet
Author: User

When we pay for Alipay, we'll bounce a dialog from the bottom, let's choose the payment method, and so on, today we're going to implement this function slowly.

Effect chart

Realize

The main interface is very simple, is a button, click to jump to pay the details of the fragment

Package Com.example.hfs.alipayuidemo;

Import android.support.v7.app.AppCompatActivity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;

public class Mainactivity extends Appcompatactivity {

 private Button Mbutton;

 @Override
 protected void onCreate (Bundle savedinstancestate) {
  super.oncreate (savedinstancestate);
  Setcontentview (r.layout.activity_main);

  Initview ();
 }

 private void Initview () {
  mbutton= (Button) This.findviewbyid (r.id.btn_pay);
  Mbutton.setonclicklistener (New View.onclicklistener () {
   @Override public
   void OnClick (view view) {

    Paydetailfragment paydetailfragment=new paydetailfragment ();
    Paydetailfragment.show (Getsupportfragmentmanager (), "paydetailfragment");}}
  );
 }


followed by the fragment code to pay the details

<?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/"
 Android "android:id=" @+id/re_root "android:layout_width=" match_parent "android:layout_height=" Match_parent " android:background= "#ffffff" > <!--================================== payment details ================================- -> <relativelayout android:id= "@+id/re_pay_detail" android:layout_width= "Match_parent" android:layout_height

   = "Fill_parent" > <scrollview android:layout_width= "match_parent" android:layout_height= "Wrap_content" > <linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:orientati on= "vertical" > <relativelayout android:layout_width= "match_parent" android:layout_height= "Wrap_conten" T "android:paddingbottom=" 15DP "android:paddingleft=" 10DP "android:paddingright=" 10DP "android:padding top= "15DP" > <imageview android:layOut_width= "10DP" android:layout_height= "10DP" android:src= "@mipmap/ic_close"/> <textview
      Droid:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_centerhorizontal= "true"
      android:text= "Order Details" android:textsize= "15sp"/> <imageview android:layout_width= "10DP" android:layout_height= "10DP" android:layout_alignparentright= "true" android:src= "@mipmap/ic_doubt"/> & lt;/relativelayout> <view android:layout_width= "match_parent" android:layout_height= "1DP" Androi d:background= "@color/line"/> <relativelayout android:layout_width= "Match_parent" Android:layout_heigh t= "Wrap_content" android:paddingbottom= "15DP" android:paddingleft= "10DP" android:paddingright= "10DP" a ndroid:paddingtop= "15DP" > <textview android:layout_width= "wrap_content" android:layout_height= "Wra" P_content "Android: text= Credit card repayment "android:textcolor=" @color/text_color_grey "/> <textview android:layout_width=" Wrap_c
      Ontent "android:layout_height=" Wrap_content "android:layout_alignparentright=" true "android:text=" abc " Android:textcolor= "@color/text_color_grey"/> </RelativeLayout> <view Android:layout_widt
     H= "Match_parent" android:layout_height= "1DP" android:background= "@color/line"/> <relativelayout Android:id= "@+id/re_pay_way" android:layout_width= "match_parent" android:layout_height= "Wrap_content" Andro Id:paddingbottom= "15DP" android:paddingleft= "10DP" android:paddingright= "10DP" android:paddingtop= "15DP"

     ; <textview android:layout_width= "wrap_content" android:layout_height= "wrap_content" payment method
      "Android:textcolor=" @color/text_color_grey "/> <textview android:layout_width=" Wrap_content " Android:layout_height= "Wrap_content" android:layout_alignparentright= "true" android:drawablepadding= "10DP" Android:dra

    wableright= "@mipmap/ic_open" android:text= "China Merchants Bank (tail 2345)" android:textcolor= "@color/text_color_grey"/> </RelativeLayout> <view android:layout_width= "match_parent" android:layout_height= "1DP" Andr oid:background= "@color/line"/> <relativelayout android:layout_width= "Match_parent" Android:layout_hei
     ght= "Wrap_content" android:paddingbottom= "15DP" android:paddingleft= "10DP" android:paddingright= "10DP" android:paddingtop= "15DP" > <textview android:layout_width= "wrap_content" android:layout_height= "W Rap_content "android:text=" Order Amount "android:textcolor=" @color/text_color_grey "/> <textview and
      Roid:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentright= "true" android:text= "10.00"Android:textcolor=" @color/text_color_grey "/> </RelativeLayout> <view Android:layout_wid
     Th= "Match_parent" android:layout_height= "1DP" android:background= "@color/line"/> <relativelayout Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:paddingbottom= "15DP" Andr oid:paddingleft= "10DP" android:paddingright= "10DP" android:paddingtop= "15DP" > <textview androi 
      D:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "payment required"/> <TextView Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_alignparentrigh T= "true" android:text= "10.00"/> </RelativeLayout> </LinearLayout> </ScrollView> & Lt
   Button android:id= "@+id/btn_confirm_pay" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:layout_aliGnparentbottom= "true" android:layout_marginbottom= "20DP" android:layout_marginleft= "10DP" Android:layout_marginri ght= "10DP" android:layout_margintop= "20DP" android:background= "@drawable/btn_click" android:padding= "10DP" and roid:text= "Confirm Payment" android:textcolor= "#ffffff"/> </RelativeLayout> <!--================================ = Payment method ======================================--> <linearlayout android:id= "@+id/lin_pay_way" Android:layout_ Width= "Match_parent" android:layout_height= "match_parent" android:layout_torightof= "@+id/re_pay_detail" Android: Background= "#ffffff" android:orientation= "vertical" android:visibility= "Gone" > <relativelayout Android:la Yout_width= "Fill_parent" android:layout_height= "wrap_content" android:background= "#ffffff" android:padding= "10DP" > <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_ Centerinparent= "true" Android:text= "Select Payment Method"/> <imageview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_alignparentright= "true" android:layout_margin= "10DP" android:src= "@mipmap/ic_close"/> </R elativelayout> <view android:layout_width= "match_parent" android:layout_height= "1DP" android:background=

   "@color/line"/> <scrollview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" > <linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" android:orientation = "vertical" > <com.example.hfs.alipayuidemo.scrollviewlistview android:id= "@+id/lv_bank" android:layou
     T_width= "Fill_parent" android:layout_height= "fill_parent" android:listselector= "#ffffff"/> <TextView
     Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:layout_margintop= "1DP" Android:background= "#fFffff "android:drawableright=" @mipmap/ic_open "android:gravity=" center_vertical "android:paddingbottom=" 15d P "android:paddingleft=" 20DP "android:paddingright=" 20DP "android:paddingtop=" 15DP "android:text=" add Bank Card "/> <view android:layout_width=" match_parent "android:layout_height=" 1DP "android:background=" @color/line "/> <relativelayout android:id=" @+id/re_balance "android:layout_width=" a ndroid:layout_height= "Wrap_content" android:layout_margintop= "1DP" android:background= "#ffffff" Android:pad Dingbottom= "10DP" android:paddingleft= "20DP" android:paddingtop= "10DP" > <imageview android:id= "@+id/img_balance" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layo Ut_centervertical= "true" android:src= "@mipmap/ic_pay_banlance_able"/> <textview android:id= "@+id/ Tv_balance "AndroiD:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_aligntop= "@+id/img_balance" android:layout_torightof= "@+id/img_balance" android:paddingleft= "10DP" android:text= "account balance" Android : textsize= "13sp"/> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_cont" Ent "android:layout_below=" @+id/tv_balance "android:layout_torightof=" @+id/img_balance "Android:paddingL" eft= "10DP" android:text= "available current account 500 Yuan" android:textsize= "10sp"/> </RelativeLayout> </linear Layout> </ScrollView> </LinearLayout> <!--==================================== Payment password ============= ============================--> <linearlayout android:id= "@+id/lin_pass" android:layout_width= "Match_parent" "Android:layout_height=" wrap_content "android:layout_torightof=" @+id/re_pay_detail "android:visibility=" Gone "and

roid:orientation= "Vertical" >  <relativelayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:paddingBott
    Om= "15DP" android:paddingleft= "10DP" android:paddingright= "10DP" android:paddingtop= "15DP" > <imageview

   Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:src= "@mipmap/ic_close"/> <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_cente Rhorizontal= "true" android:text= "Enter password"/> </RelativeLayout> <view android:layout_width= "Match_pare" 
   NT "android:layout_height=" 1DP "android:background=" @color/line "/> <edittext android:id=" @+id/pass_view " Android:layout_width= "Match_parent" android:layout_height= "48DP" android:background= "#ffffff" Android:layout_ marginleft= "40DP" android:layout_marginright= "40DP" android:layout_margintop= "10DP"/> <view android:layo
Ut_width= "Match_parent"   android:layout_height= "1DP" android:background= "@color/line"/> <textview android:layout_width= "Match_pare
   NT "android:layout_height=" Wrap_content "android:gravity=" right "android:padding=" 10DP "android:text=" Forget password "
 Android:textcolor= "@color/colorstatus" android:textsize= "12sp"/> </LinearLayout> </RelativeLayout>
Package Com.example.hfs.alipayuidemo;
Import Android.app.Dialog;
Import Android.os.Bundle;
Import Android.support.annotation.NonNull;
Import android.support.v4.app.DialogFragment;
Import android.view.Gravity;
Import Android.view.View;
Import Android.view.Window;
Import Android.view.WindowManager;
Import android.view.animation.Animation;
Import Android.view.animation.AnimationUtils;
Import Android.widget.Button;
Import Android.widget.EditText;
Import Android.widget.LinearLayout;
Import Android.widget.ListView;


Import Android.widget.RelativeLayout; /** * Bottom Window Fragment */public class Paydetailfragment extends Dialogfragment {private Relativelayout Repayway, Repaydet
 AIL, rebalance;
 Private LinearLayout Linpayway,linpass;
 Private ListView LV;
 Private Button Btnpay;
 Private EditText Gridpasswordview; @NonNull @Override public Dialog oncreatedialog (Bundle savedinstancestate) {//using a constructor with no theme, the Dialog border is still a few millimeters from the screen.
  。 Dialog Dialog = new Dialog (getactivity (), R.style.bottoMdialog); Dialog.requestwindowfeature (Window.feature_no_title);
  Set the content before setting Dialog.setcontentview (R.layout.fragment_pay_detail); Dialog.setcanceledontouchoutside (TRUE);
  External click cancel//Set width to screen wide, close to bottom of screen.
  final window window = Dialog.getwindow ();
  Window.setwindowanimations (R.style.animbottom);
  Final Windowmanager.layoutparams LP = Window.getattributes (); lp.gravity = Gravity.bottom; Cling to bottom lp.width = WindowManager.LayoutParams.MATCH_PARENT;
  Width flat lp.height = getactivity (). Getwindowmanager (). Getdefaultdisplay (). GetHeight () * 3/5;
  Window.setattributes (LP);
  Repayway = (relativelayout) Dialog.findviewbyid (R.id.re_pay_way); Repaydetail = (relativelayout) Dialog.findviewbyid (r.id.re_pay_detail);//payment details Linpayway = (linearlayout)
  Dialog.findviewbyid (R.id.lin_pay_way);//payment Method LV = (ListView) Dialog.findviewbyid (R.id.lv_bank);//payment Method (bank card list) rebalance = (relativelayout) Dialog.findviewbyid (r.id.re_balance);//payment Method (balance) Btnpay = (Button) Dialog.findviewbyid ( R.id.btN_confirm_pay);
  Gridpasswordview = (edittext) Dialog.findviewbyid (R.id.pass_view);
  Linpass = (linearlayout) Dialog.findviewbyid (R.id.lin_pass);
  Repayway.setonclicklistener (listener);
  Rebalance.setonclicklistener (listener);
  Btnpay.setonclicklistener (listener);
 return dialog; } View.onclicklistener Listener = new View.onclicklistener () {@Override public void OnClick (view view) {Animati
   On slide_left_to_left = Animationutils.loadanimation (Getactivity (), r.anim.slide_left_to_left);
   Animation slide_right_to_left = animationutils.loadanimation (Getactivity (), r.anim.slide_right_to_left);
   Animation slide_left_to_right = animationutils.loadanimation (Getactivity (), r.anim.slide_left_to_right);
   Animation slide_left_to_left_in = animationutils.loadanimation (Getactivity (), r.anim.slide_left_to_left_in);
     Switch (View.getid ()) {case r.id.re_pay_way:repaydetail.startanimation (slide_left_to_left);
     Repaydetail.setvisibility (View.gone); Linpayway.staRtanimation (Slide_right_to_left);
     Linpayway.setvisibility (view.visible);
    Break
     Case R.id.re_balance:repaydetail.startanimation (slide_left_to_left_in);
     Repaydetail.setvisibility (view.visible);
     Linpayway.startanimation (Slide_left_to_right);
     Linpayway.setvisibility (View.gone);
    Break
     Case R.id.btn_confirm_pay:repaydetail.startanimation (Slide_left_to_left);
     Repaydetail.setvisibility (View.gone);
     Linpass.startanimation (Slide_right_to_left);
     Linpass.setvisibility (view.visible);
    Break
   Default:break;
}
  }
 };

 }

There is also a problem with ScrollView nesting listview, mainly to rewrite the ListView calculation height

Package Com.example.hfs.alipayuidemo;

Import Android.content.Context;
Import Android.util.AttributeSet;
Import Android.widget.ListView;

/**
 * ScrollView nested ListView, override ListView compute height/Public
 class Scrollviewlistview extends ListView
{
 Public Scrollviewlistview {
  super (context);
 }

 Public Scrollviewlistview (context, AttributeSet attrs) {
  Super (context, attrs);
 }

 Public Scrollviewlistview (context, AttributeSet attrs, int defstyleattr) {
  Super (context, attrs, defstyleattr);
 }

 protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {

  int expandspec = Measurespec.makemeasurespec (Integer.max_value >> 2,

    measurespec.at_most);

  Super.onmeasure (Widthmeasurespec, Expandspec);

 }


Well, actually it's quite understandable, attached GitHub project address: Https://github.com/Greathfs/AliPayUiDemo

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.