80,472
社区成员




<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff" >
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:text="测试"
/>
</LinearLayout>
float_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/rlfloatView"
android:layout_width="200px"
android:background="#F42B2B"
android:layout_gravity="center"
android:layout_height="200px" >
<Button
android:layout_width="100px"
android:layout_height="100px"
android:layout_centerInParent="true"
/>
</RelativeLayout>
</LinearLayout>
activity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//loadText(); //commend by danielinbiti
layoutFloat();
}
private void layoutFloat(){
setContentView(R.layout.test_float);
LinearLayout.LayoutParams lp =
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
this.addContentView(getFloatView(),lp);
}
private void moveFloat(){
RelativeLayout rl = (RelativeLayout)findViewById(R.id.rlfloatView);
rl.setTop(rl.getTop()+10);
rl.setLeft(rl.getLeft()+10);
rl.setRight(rl.getRight()+10);
rl.setBottom(rl.getBottom()+10);
}
private View getFloatView(){
return LayoutInflater.from(this).inflate(R.layout.float_layout, null);
}
public boolean onTouchEvent(MotionEvent event){
//点击事件没处理拖动,只是一个方式 comment by danielinbiti 20130830
if(event.getAction()==MotionEvent.ACTION_DOWN){
this.moveFloat();
}
return super.onTouchEvent(event);
}