求助!slidingMenu的跳转问题! xml页面跳转slidingMenu 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LiftNewsActivity对应的XML文件 slidingmenu_left.xml<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="@drawable/bg_slidingmenu_left" android:gravity="center" android:orientation="vertical" android:paddingBottom="40dp" android:paddingLeft="60dp" android:paddingTop="20dp" > <!-- 11111111 --> <RelativeLayout android:id="@+id/rlivtv1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:paddingTop="20dp" > <ImageView android:id="@+id/imageView1" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/biz_navigation_tan_home" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/imageView1" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/imageView1" android:text="首 页" android:textColor="#99ffffff" android:textSize="18dp" /> </RelativeLayout> <!-- 222222 --> <RelativeLayout android:id="@+id/rlivtv2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" android:focusable="true" android:paddingTop="20dp" > <ImageView android:id="@+id/imageView2" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/biz_navigation_tan_news" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/imageView2" android:gravity="center" android:text="新 闻" android:textColor="#99ffffff" android:textSize="18dp" /> </RelativeLayout> <!-- 3333333 --> <RelativeLayout android:id="@+id/rlivtv3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" android:focusable="true" android:paddingTop="20dp" > <ImageView android:id="@+id/imageView3" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/biz_navigation_tan_affairs" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/imageView3" android:gravity="center" android:text="政 务" android:textColor="#99ffffff" android:textSize="18dp" /> </RelativeLayout> <!-- 4444444 --> <RelativeLayout android:id="@+id/rlivtv4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" android:focusable="true" android:paddingTop="20dp" > <ImageView android:id="@+id/imageView4" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/biz_navigation_tan_live" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/imageView4" android:gravity="center" android:text="直 播" android:textColor="#99ffffff" android:textSize="18dp" /> </RelativeLayout> <!-- 55555555 --> <RelativeLayout android:id="@+id/rlivtv5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" android:focusable="true" android:paddingTop="20dp" > <ImageView android:id="@+id/imageView5" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/biz_navigation_tan_demand" /> <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/imageView5" android:gravity="center" android:text="点 播" android:textColor="#99ffffff" android:textSize="18dp" /> </RelativeLayout> <!-- 66666666 --> <RelativeLayout android:id="@+id/rlivtv6" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" android:focusable="true" android:paddingTop="20dp" > <ImageView android:id="@+id/imageView6" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/biz_navigation_tan_project" /> <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/imageView6" android:gravity="center" android:text="专 题" android:textColor="#99ffffff" android:textSize="18dp" /> </RelativeLayout> <!-- 777777777 --> <RelativeLayout android:id="@+id/rlivtv7" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" android:focusable="true" android:paddingTop="20dp" > <ImageView android:id="@+id/imageView7" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/biz_navigation_tan_image" /> <TextView android:id="@+id/textView7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/imageView7" android:gravity="center" android:text="图 片" android:textColor="#99ffffff" android:textSize="18dp" /> </RelativeLayout> <!-- 88888888 --> <RelativeLayout android:id="@+id/rlivtv8" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" android:focusable="true" android:paddingTop="20dp" > <ImageView android:id="@+id/imageView8" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/biz_navigation_tan_radio" /> <TextView android:id="@+id/textView8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/imageView8" android:gravity="center" android:text="广 播" android:textColor="#99ffffff" android:textSize="18dp" /> </RelativeLayout> <!-- 99999999 --> <RelativeLayout android:id="@+id/rlivtv9" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" android:focusable="true" android:paddingTop="20dp" > <ImageView android:id="@+id/imageView9" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/biz_navigation_tan_subscribe" /> <TextView android:id="@+id/textView9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/imageView9" android:gravity="center" android:text="订 阅" android:textColor="#99ffffff" android:textSize="18dp" /> </RelativeLayout></LinearLayout> 因为左边的menu。xml的按钮没有加点击事件切换fragment 用着这个库很简单:首先,思想是点击导航,把导航需要显示的布局fragmen替换到主布局文件中布局,用replace方法替换。你先搜一下fragmen怎么用,再搜下这个方法replace(),应该就差不多了。 这个页面的跳转不是activity的跳转而是fragment的相互切换,需要用的是replace方法,而你用了intent,这是不可行的。你先了解下fragment再看看代码就明白了。我给你贴个我写的//左侧导航栏点击事件 public void menuItemClicked(int position) { menu.showContent();// 点击关闭 switch (position) { case 0: Toast.makeText(getApplicationContext(), "遥信检测", 0).show(); fragmentManager.beginTransaction() .replace(R.id.homefragment, new HomeFragment()).commit(); break; case 1: Toast.makeText(getApplicationContext(), "遥控监测", 0).show(); fragmentManager.beginTransaction() .replace(R.id.homefragment, new YaokongFragment()).commit(); break; case 2: Toast.makeText(getApplicationContext(), "载波通信", 0).show(); fragmentManager.beginTransaction() .replace(R.id.homefragment, new ZaibotongxinFragment()) .commit(); break; case 3: Toast.makeText(getApplicationContext(), "信号强度", 0).show(); fragmentManager.beginTransaction() .replace(R.id.homefragment, new XinhaoqiangduFragment()) .commit(); break; case 4: Toast.makeText(getApplicationContext(), "电表抄读", 0).show(); fragmentManager.beginTransaction() .replace(R.id.homefragment, new DianbiaochaoduFragment()) .commit(); break; case 5: Toast.makeText(getApplicationContext(), "脉冲检测", 0).show(); fragmentManager.beginTransaction() .replace(R.id.homefragment, new MaichongjianceFragment()) .commit(); break; default: break; } 其中还有fragment的管理器没贴上去,你先看下吧 跪求 android 实现 流媒体 播放远程mp3文件 代码 ListView优化问题,求解 android 动态墙纸 怎么用openGL播放视频啊 AppWidget不能更新 MapView 安卓API KEY 无法申请 android mediaplayer问题 android开发,LED灯(不是相机闪光灯,而是屏幕前面的指示灯)无法打开! editText1的OnKey事件为什么执行两次Toast?怎么可以避免 加载图片的问题 viewpager多页隐藏的问题 运行时控制台总是出现emulator-5554 disconnected
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="@drawable/bg_slidingmenu_left"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="40dp"
android:paddingLeft="60dp"
android:paddingTop="20dp" > <!-- 11111111 --> <RelativeLayout
android:id="@+id/rlivtv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="20dp" > <ImageView
android:id="@+id/imageView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/biz_navigation_tan_home" /> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView1"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/imageView1"
android:text="首 页"
android:textColor="#99ffffff"
android:textSize="18dp" />
</RelativeLayout> <!-- 222222 --> <RelativeLayout
android:id="@+id/rlivtv2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingTop="20dp" > <ImageView
android:id="@+id/imageView2"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/biz_navigation_tan_news" /> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/imageView2"
android:gravity="center"
android:text="新 闻"
android:textColor="#99ffffff"
android:textSize="18dp" />
</RelativeLayout>
<!-- 3333333 --> <RelativeLayout
android:id="@+id/rlivtv3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingTop="20dp" > <ImageView
android:id="@+id/imageView3"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/biz_navigation_tan_affairs" /> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/imageView3"
android:gravity="center"
android:text="政 务"
android:textColor="#99ffffff"
android:textSize="18dp" />
</RelativeLayout>
<!-- 4444444 --> <RelativeLayout
android:id="@+id/rlivtv4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingTop="20dp" > <ImageView
android:id="@+id/imageView4"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/biz_navigation_tan_live" /> <TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/imageView4"
android:gravity="center"
android:text="直 播"
android:textColor="#99ffffff"
android:textSize="18dp" />
</RelativeLayout>
<!-- 55555555 --> <RelativeLayout
android:id="@+id/rlivtv5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingTop="20dp" > <ImageView
android:id="@+id/imageView5"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/biz_navigation_tan_demand" /> <TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/imageView5"
android:gravity="center"
android:text="点 播"
android:textColor="#99ffffff"
android:textSize="18dp" />
</RelativeLayout>
<!-- 66666666 --> <RelativeLayout
android:id="@+id/rlivtv6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingTop="20dp" > <ImageView
android:id="@+id/imageView6"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/biz_navigation_tan_project" /> <TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/imageView6"
android:gravity="center"
android:text="专 题"
android:textColor="#99ffffff"
android:textSize="18dp" />
</RelativeLayout>
<!-- 777777777 --> <RelativeLayout
android:id="@+id/rlivtv7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingTop="20dp" > <ImageView
android:id="@+id/imageView7"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/biz_navigation_tan_image" /> <TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/imageView7"
android:gravity="center"
android:text="图 片"
android:textColor="#99ffffff"
android:textSize="18dp" />
</RelativeLayout>
<!-- 88888888 --> <RelativeLayout
android:id="@+id/rlivtv8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingTop="20dp" > <ImageView
android:id="@+id/imageView8"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/biz_navigation_tan_radio" /> <TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/imageView8"
android:gravity="center"
android:text="广 播"
android:textColor="#99ffffff"
android:textSize="18dp" />
</RelativeLayout>
<!-- 99999999 --> <RelativeLayout
android:id="@+id/rlivtv9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clickable="true"
android:focusable="true"
android:paddingTop="20dp" > <ImageView
android:id="@+id/imageView9"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/biz_navigation_tan_subscribe" /> <TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/imageView9"
android:gravity="center"
android:text="订 阅"
android:textColor="#99ffffff"
android:textSize="18dp" />
</RelativeLayout></LinearLayout>
首先,思想是点击导航,把导航需要显示的布局fragmen替换到主布局文件中布局,用replace方法替换。你先搜一下fragmen怎么用,再搜下这个方法replace(),应该就差不多了。
public void menuItemClicked(int position) {
menu.showContent();// 点击关闭
switch (position) {
case 0:
Toast.makeText(getApplicationContext(), "遥信检测", 0).show();
fragmentManager.beginTransaction()
.replace(R.id.homefragment, new HomeFragment()).commit();
break;
case 1:
Toast.makeText(getApplicationContext(), "遥控监测", 0).show();
fragmentManager.beginTransaction()
.replace(R.id.homefragment, new YaokongFragment()).commit();
break;
case 2:
Toast.makeText(getApplicationContext(), "载波通信", 0).show();
fragmentManager.beginTransaction()
.replace(R.id.homefragment, new ZaibotongxinFragment())
.commit();
break;
case 3:
Toast.makeText(getApplicationContext(), "信号强度", 0).show();
fragmentManager.beginTransaction()
.replace(R.id.homefragment, new XinhaoqiangduFragment())
.commit();
break;
case 4:
Toast.makeText(getApplicationContext(), "电表抄读", 0).show();
fragmentManager.beginTransaction()
.replace(R.id.homefragment, new DianbiaochaoduFragment())
.commit();
break;
case 5:
Toast.makeText(getApplicationContext(), "脉冲检测", 0).show();
fragmentManager.beginTransaction()
.replace(R.id.homefragment, new MaichongjianceFragment())
.commit();
break;
default:
break;
}