setLayoutParams不生效,请大家指点

大家好,
             我想实现能改变menu_layout的位置,使用如下代码实现,但运行没有效果,请大家指导下,谢谢。

protected void onCreate(Bundle savedInstanceState) {
         
  
		super.onCreate(savedInstanceState); 
		setContentView(R.layout.activity_main); 
	} 
	 
	@Override 
	public boolean onTouchEvent( MotionEvent event) {
         
  
		RelativeLayout layout  = (RelativeLayout) this.getLayoutInflater().inflate(R.layout.activity_main, null); 
		LinearLayout menu_layout = (LinearLayout)layout.findViewById(R.id.menu); 
	        mp  =  (MarginLayoutParams)menu_layout.getLayoutParams();   
		mp.leftMargin=200; 
		mp.topMargin=200; 
	        menu_layout.setLayoutParams(mp); 
		return true; 
	}





布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    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:orientation="horizontal" 
    tools:context=".MainActivity" > 
	<LinearLayout 
	      	android:layout_width="fill_parent" 
   		  	android:layout_height="fill_parent" 
   		 	android:background="#f00"  
   			android:id="@+id/menu"> 
	     
	    <TextView 
	        android:id="@+id/text" 
	        android:layout_width="wrap_content" 
	        android:layout_height="wrap_content" 
	        android:text="@string/hello_world" /> 
 
	</LinearLayout>     
	 
    <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:text="hello" /> 
     
 
</RelativeLayout>

经验分享 程序员 微信小程序 职场和发展