bringChildToFront()将view显示在屏幕最前方

1.public abstract void bringChildToFront (View child)
1)作用是把该视图置于其他所有子视图之上,如在FrameLayout中切换被叠放的视图。
2)该方法出自public interface ViewParent
Java代码 复制代码  收藏代码
  1. import android.app.Activity;   
  2. import android.app.AlertDialog;   
  3. import android.content.DialogInterface;   
  4. import android.os.Bundle;   
  5. import android.text.style.AbsoluteSizeSpan;   
  6. import android.util.Log;   
  7. import android.view.MotionEvent;   
  8. import android.view.View;   
  9. import android.view.View.OnClickListener;   
  10. import android.view.View.OnTouchListener;   
  11. import android.widget.AbsoluteLayout;   
  12. import android.widget.Button;   
  13.   
  14. public class HelloWorld2 extends Activity {   
  15.     /** Called when the activity is first created. */  
  16.        
  17.     AbsoluteLayout mLayoutGroup = null;   
  18.     @Override  
  19.     public void onCreate(Bundle savedInstanceState) {   
  20.         super.onCreate(savedInstanceState);   
  21.         //setContentView(R.layout.main);   
  22.            
  23.         mLayoutGroup = new AbsoluteLayout(this);   
  24.         AbsoluteLayout.LayoutParams layoutParams = new AbsoluteLayout.LayoutParams   
  25.         (32048000);   
  26.            
  27.         setContentView(mLayoutGroup, layoutParams);   
  28.            
  29.         Button button= new Button(this);   
  30.         button.setText("testButton");   
  31.         layoutParams = new AbsoluteLayout.LayoutParams(120602020);   
  32.         mLayoutGroup.addView(button, layoutParams);   
  33.         button.setOnTouchListener(touchListener);   
  34.            
  35.         final Button btButton = new Button(this);   
  36.         btButton.setText("测试按钮移动");   
  37.         layoutParams = new AbsoluteLayout.LayoutParams(1206020160);   
  38.         mLayoutGroup.addView(btButton, layoutParams);   
  39.         btButton.setOnTouchListener(touchListener);   
  40.     }   
  41.        
  42.     OnTouchListener touchListener = new OnTouchListener()   
  43.     {   
  44.         int temp[] = new int[]{00};   
  45.         public boolean onTouch(View arg0, MotionEvent arg1) {   
  46.             // TODO Auto-generated method stub  
  47.             int eventAction = arg1.getAction();   
  48.             Log.e("testButtonMove""OnTouchAction:"+eventAction);   
  49.                
  50.             int x = (int)arg1.getRawX();   
  51.             int y = (int)arg1.getRawY();   
  52.                
  53.             switch (eventAction) {   
  54.             case MotionEvent.ACTION_DOWN:   
  55.                    
  56.                 temp[0] = (int)arg1.getX();   
  57.                 temp[1] = (int)(y-arg0.getTop());      
  58.                    
  59.                 mLayoutGroup.bringChildToFront(arg0);   
  60.                 arg0.postInvalidate();   
  61.                    
  62.                 break;   
  63.             case MotionEvent.ACTION_MOVE:   
  64.                    
  65.                 int left = x - temp[0];   
  66.                 int top = y - temp[1];   
  67.                 int right = left + arg0.getWidth();   
  68.                 int bottom = top + arg0.getHeight();   
  69.                    
  70.                 arg0.layout(left, top, right, bottom);   
  71.                 arg0.postInvalidate();   
  72.                    
  73.                 break;   
  74.   
  75.             default:   
  76.                 break;   
  77.             }   
  78.                
  79.             return false;   
  80.         }   
  81.     };   
  82. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值