以下MainActivity的代码:
主UI布局
运行后:
点击界面的Button(不是侧边栏的按钮)
搞不懂了。。。。求大神解答一二
public class MainActivity extends Activity {
private SlidingMenu slidingMenu;
private Button btn_tabhost;
private Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_tabhost=(Button) findViewById(R.id.btn_tabhost);
btn1=(Button) findViewById(R.id.btn1);
slidingMenu=new SlidingMenu(this);
//左边出来
slidingMenu.setMode(SlidingMenu.LEFT);
//设置slidingmenu的尺寸
slidingMenu.setBehindOffsetRes(R.dimen.sliding_menu_offset);
//设置该slidingmenu全屏都可拖出来
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
//绑定slidingmenu到当前activity
slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
//设置slidingmenu的布局
slidingMenu.setMenu(R.layout.slidingmenu);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent1=new Intent(MainActivity.this,TabHostActivity2.class);
startActivity(intent1);
}
});
}
主UI布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="com.jikexueyuan.usingslidingmenu.MainActivity"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/blackground"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="57dp"
android:textColor="#fffafa"
android:textSize="80px"
android:text="Welcome" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="Button" />
</RelativeLayout>
运行后:
![](http://img.bbs.csdn.net/upload/201509/19/1442626270_330636.png)
点击界面的Button(不是侧边栏的按钮)
![](http://img.bbs.csdn.net/upload/201509/19/1442626319_44850.png)
搞不懂了。。。。求大神解答一二