标签:
package
com.wang.main;
import
android.graphics.Bitmap;
import
android.graphics.BitmapFactory;
import
android.support.v7.app.AppCompatActivity;
import
android.os.Bundle;
import
android.util.Log;
import
android.view.DragEvent;
import
android.view.View;
import
android.widget.Button;
import
android.widget.ImageView;
import
android.widget.LinearLayout;
import
android.widget.ScrollView;
import
android.widget.TextView;
import
android.widget.Toast;
import
com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
public
class
MainActivity
extends
AppCompatActivity
implements
View.OnClickListener {
private
SlidingMenu sliding;
private
ImageView iv;
private
LinearLayout layout1,layout2,layout3;
private
TextView bottom_tv1,bottom_tv2;
private
ScrollView scrollview;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//1.初始化slidingmenu对象
sliding=
new
SlidingMenu(
this
);
//2、设置slidingmenu的显示方式,left=只有左侧菜单,rigth=只有右侧菜单,LEFT_RIGHT=既能显示左侧,又能显示右侧
sliding.setMode(SlidingMenu.LEFT);
//3、设置slidingmenu的菜单布局
sliding.setMenu(R.layout.slidingleft);
initView();
//4、设置菜单的显示方式
// /*
// *SlidingMenu.TOUCHMODE_FULLSCREEN 在屏幕的任意位置滑动即可打开侧滑菜单
// * SlidingMenu.TOUCHMODE_MARGIN 必须从边缘开始滑动才能打开侧滑菜单
// * SlidingMenu.TOUCHMODE_NONE 无论在什么位置滑动都不能打开侧滑菜单,必须通过点击按钮,手动调用打开菜单的方法
// * */
sliding.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
//5、设置滑动菜单的隐藏方式
sliding.setTouchModeBehind(SlidingMenu.TOUCHMODE_MARGIN);
//6、设置菜单显示宽度,设为屏幕的1/3
int
i=getResources().getDisplayMetrics().widthPixels*
2
/
3
;
sliding.setBehindWidth(i);
//设置内容与菜单边缘的阴影效果
sliding.setShadowDrawable(getResources().getDrawable(R.drawable.shape_sdshadowdraw));
sliding.setShadowWidth(
30
);
//设置菜单的透明度的改变,其中setFadeEnabled默认值为true
// sliding.setFadeEnabled(false);
sliding.setFadeDegree(
1
.0f);
//0-1,其中0表示,拉动菜单滚动时先出现的是菜单的开头控件,1表示先出现末尾控件,默认0.5
sliding.setBehindScrollScale(
0
.5f);
//7、将菜单添加到当前activity中显示
// /*
// * SlidingMenu.SLIDING_WINDOW 以窗口方式将侧滑菜单加到当前Activity中
// * SlidingMenu.SLIDING_CONTENT 以内容方式将侧滑菜单加到当前Activity中
// * 两者的区别在于是否共享标题栏
// * */
sliding.attachToActivity(
this
,SlidingMenu.SLIDING_WINDOW);
//本来是要联网读取数据,并将图片弄成圆形的,现在手动画一下
GetRoundBitmap gp=
new
GetRoundBitmap();
Bitmap bp=gp.getRoundBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.naruto));
Log.i(
"mtag"
,
"start"
+bp);
Log.i(
"mtag"
,
"start"
+iv);
iv.setImageBitmap(bp);
}
/**
* 寻找控件
*
*@author WangShujie
*created at 2016/4/23 18:59
*/
private
void
initView() {
iv= (ImageView)sliding.getMenu().findViewById(R.id.slidingleft_iv);
layout1= (LinearLayout) sliding.getMenu().findViewById(R.id.slidingleft_layout1);
layout2=(LinearLayout) sliding.getMenu().findViewById(R.id.slidingleft_layout2);
layout3=(LinearLayout) sliding.getMenu().findViewById(R.id.slidingleft_layout3);
bottom_tv1= (TextView) sliding.getMenu().findViewById(R.id.sliding_botomtv1);
bottom_tv2= (TextView) sliding.getMenu().findViewById(R.id.sliding_botomtv2);
scrollview= (ScrollView) sliding.getMenu().findViewById(R.id.slidingleft_lv);
layout1.setOnClickListener(
this
);
layout2.setOnClickListener(
this
);
layout3.setOnClickListener(
this
);
bottom_tv1.setOnClickListener(
this
);
bottom_tv2.setOnClickListener(
this
);
}
/**
*对控件进行监听
*
*@author WangShujie
*created at 2016/4/23 19:31
*/
@Override
public
void
onClick(View v) {
switch
(v.getId()){
case
R.id.slidingleft_layout1:
Toast.makeText(MainActivity.
this
,
"你点击了我的好友"
, Toast.LENGTH_SHORT).show();
break
;
case
R.id.slidingleft_layout2:
Toast.makeText(MainActivity.
this
,
"你点击了我的收藏"
, Toast.LENGTH_SHORT).show();
break
;
case
R.id.slidingleft_layout3:
Toast.makeText(MainActivity.
this
,
"你点击了退出"
, Toast.LENGTH_SHORT).show();
break
;
case
R.id.sliding_botomtv1:
Toast.makeText(MainActivity.
this
,
"你点击了设置1"
, Toast.LENGTH_SHORT).show();
break
;
case
R.id.sliding_botomtv2:
Toast.makeText(MainActivity.
this
,
"你点击了设置2"
, Toast.LENGTH_SHORT).show();
break
;
}
}
}
package
com.wang.main;
import
android.graphics.Bitmap;
import
android.graphics.BitmapFactory;
import
android.os.Bundle;
import
android.util.Log;
import
android.view.View;
import
android.widget.ImageView;
import
android.widget.LinearLayout;
import
android.widget.ScrollView;
import
android.widget.TextView;
import
android.widget.Toast;
import
com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import
com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import
com.wang.main.GetRoundBitmap;
public
class
MainActivity
extends
SlidingFragmentActivity
implements
View.OnClickListener {
private
SlidingMenu sliding;
private
ImageView iv;
private
LinearLayout layout1,layout2,layout3;
private
TextView bottom_tv1,bottom_tv2;
private
ScrollView scrollview;
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
//设置页面显示内容,不包括菜单
setContentView(R.layout.activity_main);
//1、将继承的Activity替换为框架中的SlidingFragmentActivity
//2、调用setBehindContentView设置菜单的显示
setBehindContentView(R.layout.slidingleft);
//3、获取SlidingFragmentActivity中自带的菜单对象
sliding=getSlidingMenu();
initView();
//4、设置slidingmenu的显示方式,left=只有左侧菜单,rigth=只有右侧菜单,LEFT_RIGHT=既能显示左侧,又能显示右侧
sliding.setMode(SlidingMenu.LEFT);
//5、设置菜单的显示方式
// /*
// *SlidingMenu.TOUCHMODE_FULLSCREEN 在屏幕的任意位置滑动即可打开侧滑菜单
// * SlidingMenu.TOUCHMODE_MARGIN 必须从边缘开始滑动才能打开侧滑菜单
// * SlidingMenu.TOUCHMODE_NONE 无论在什么位置滑动都不能打开侧滑菜单,必须通过点击按钮,手动调用打开菜单的方法
// * */
sliding.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
//6、设置滑动菜单的隐藏方式
sliding.setTouchModeBehind(SlidingMenu.TOUCHMODE_MARGIN);
//7、设置菜单显示宽度,设为屏幕的1/3
int
i=getResources().getDisplayMetrics().widthPixels*
2
/
3
;
sliding.setBehindWidth(i);
//设置内容与菜单边缘的阴影效果
sliding.setShadowDrawable(getResources().getDrawable(R.drawable.shape_sdshadowdraw));
sliding.setShadowWidth(
30
);
//设置菜单的透明度的改变,其中setFadeEnabled默认值为true
// sliding.setFadeEnabled(false);
sliding.setFadeDegree(
1
.0f);
//0-1,其中0表示,拉动菜单滚动时先出现的是菜单的开头控件,1表示先出现末尾控件,默认0.5
sliding.setBehindScrollScale(
0
.5f);
//本来是要联网读取数据,并将图片弄成圆形的,现在手动画一下
GetRoundBitmap gp=
new
GetRoundBitmap();
Bitmap bp=gp.getRoundBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.naruto));
Log.i(
"mtag"
,
"start"
+bp);
Log.i(
"mtag"
,
"start"
+iv);
iv.setImageBitmap(bp);
}
/**
* 寻找控件
*
*@author WangShujie
*created at 2016/4/23 18:59
*/
private
void
initView() {
iv= (ImageView)sliding.getMenu().findViewById(R.id.slidingleft_iv);
layout1= (LinearLayout) sliding.getMenu().findViewById(R.id.slidingleft_layout1);
layout2=(LinearLayout) sliding.getMenu().findViewById(R.id.slidingleft_layout2);
layout3=(LinearLayout) sliding.getMenu().findViewById(R.id.slidingleft_layout3);
bottom_tv1= (TextView) sliding.getMenu().findViewById(R.id.sliding_botomtv1);
bottom_tv2= (TextView) sliding.getMenu().findViewById(R.id.sliding_botomtv2);
scrollview= (ScrollView) sliding.getMenu().findViewById(R.id.slidingleft_lv);
Log.i(
"mtag"
,
"tianfuxiaoyan++iv===="
+iv);
Log.i(
"mtag"
,
"tianfuxiaoyan++layout1===="
+layout1);
Log.i(
"mtag"
,
"tianfuxiaoyan++bottom_tv1===="
+bottom_tv1);
layout1.setOnClickListener(
this
);
layout2.setOnClickListener(
this
);
layout3.setOnClickListener(
this
);
bottom_tv1.setOnClickListener(
this
);
bottom_tv2.setOnClickListener(
this
);
}
/**
*对控件进行监听
*
*@author WangShujie
*created at 2016/4/23 19:31
*/
@Override
public
void
onClick(View v) {
switch
(v.getId()){
case
R.id.slidingleft_layout1:
Toast.makeText(MainActivity.
this
,
"你点击了我的好友"
, Toast.LENGTH_SHORT).show();
break
;
case
R.id.slidingleft_layout2:
Toast.makeText(MainActivity.
this
,
"你点击了我的收藏"
, Toast.LENGTH_SHORT).show();
break
;
case
R.id.slidingleft_layout3:
Toast.makeText(MainActivity.
this
,
"你点击了退出"
, Toast.LENGTH_SHORT).show();
break
;
case
R.id.sliding_botomtv1:
Toast.makeText(MainActivity.
this
,
"你点击了设置1"
, Toast.LENGTH_SHORT).show();
break
;
case
R.id.sliding_botomtv2:
Toast.makeText(MainActivity.
this
,
"你点击了设置2"
, Toast.LENGTH_SHORT).show();
break
;
}
}
}
标签:
原文地址:http://blog.csdn.net/tianfuxiaoyan/article/details/51235837