SlideMenu实现 第三方 需要导入moudle(slidemenu)
SlideMenu实现抽屉
1.SlideMenu的属性:
设置模式: setMode(SlidingMenu.LEFT);
设置触摸屏幕的模式:setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
//TOUCHMODE_FULLSCREEN全屏;TOUCHMODE_MARGIN边界;TOUCHMODE_NONE不能滑动
设置左侧菜单滑动显示的内容:slidingMenu.setMenu(R.layout.slide_menu);
设置左侧滑动菜单的阴影宽度:slidingMenu.setShadowWidth(300);
设置滑动时的渐变程度:slidingMenu.setFadeDegree(0.5f);范围0.0f-1.0f
设置淡入淡出的效果:slidingMenu.setFadeEnabled(true);
设置左侧滑动菜单的阴影图片(颜色):setShadowDrawable();
设置滑出时主页面显示的剩余宽度:slidingMenu.setBehindOffset(200);
注意:
(1)attachToActivity():将slidemenu和Activity绑定
(2)setMenu():设置菜单显示的内容
(3) Button bt = slidingMenu.getMenu().findViewById(R.id.bt1);为侧滑出来的菜单设置事件监听
2.代码实现:
(1).导入第三方moudle:slidemenu
(2) activity代码中实现:
private void initMenu() {
slidingMenu = new SlidingMenu(this);
slidingMenu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT);
//从那边出来
slidingMenu.setMode(SlidingMenu.LEFT);
View view = LayoutInflater.from(this).inflate(R.layout.slids_layout,null);
TextView textView1 = view.findViewById(R.id.t1);
textView1.setOnClickListener(this);
TextView textView2 = view.findViewById(R.id.t2);
textView2.setOnClickListener(this);
TextView textView3 = view.findViewById(R.id.t3);
textView3.setOnClickListener(this);
slidingMenu.setMenu(view);
//剩余200px
slidingMenu.setBehindOffset(200);
//拉哪都不行
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
slidingMenu.setOnOpenedListener(new SlidingMenu.OnOpenedListener() {
@Override
public void onOpened() {
Toast.makeText(MainActivity.this, "抽屉拉开了", Toast.LENGTH_SHORT).show();
}
});
slidingMenu.setOnClosedListener(new SlidingMenu.OnClosedListener() {
@Override
public void onClosed() {
Toast.makeText(MainActivity.this, "抽屉关上了", Toast.LENGTH_SHORT).show();
}
});
}
SufaceView
双缓冲:
MediaPlayer和SurfaceView高级应用 播放视频和弹幕
效果
一.思路:
采用SurfaceView控件,因为需要频繁的更新UI,需要2个SurfaceView,一个用于播放视频,一个用于发送弹幕
二.代码
1.xml布局代码
<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"
tools:context=".MainActivity"
android:orientation="vertical">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:layout_centerInParent="true"
android:layout_height="500dp"
android:layout_width="300dp"
android:id="@+id/vidio"/>
</RelativeLayout>
<SurfaceView
android:id="@+id/sfv"
android:layout_width="match_parent"
android:layout_height="500dp"/>
</FrameLayout>
<LinearLayout
android:layout_below="@id/frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发 送"
android:textSize="20dp"/>
</LinearLayout>
2.Java代码
mediaPlayer.reset();//重置
try {
mediaPlayer.setDataSource("/sdcard/Video/蔡徐坤.mp4");
mediaPlayer.prepareAsync();//异步准备 网络资源
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
});
} catch (IOException e) {
e.printStackTrace();
}
btn = findViewById(R.id.btn);
et = findViewById(R.id.et);
surfaceView = findViewById(R.id.sfv);
surfaceView_vidio = findViewById(R.id.vidio);
//视频的
surfaceHolder_vidio = surfaceView_vidio.getHolder();
surfaceHolder_vidio.addCallback(this);
//弹幕的
surfaceHolder = surfaceView.getHolder();//获得holder
surfaceHolder.addCallback(this);//添加回调,获取声明周期
//将弹幕变成透明
surfaceView.setZOrderOnTop(true);
surfaceHolder.setFormat(PixelFormat.TRANSLUCENT);//透明
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuffer sb = new StringBuffer();
sb.append("#");
for(int i =0;i<6;i++){
sb.append(str[random.nextInt(str.length)]);
}
String s = et.getText().toString();
int y = random.nextInt(400);
list.add(new DanMuBean(s,x,y,sb.toString()));
}
});
}
//创建了
@Override
public void surfaceCreated(SurfaceHolder holder) {
if(holder==surfaceHolder_vidio){
//将视频放到holder里面播放
mediaPlayer.setDisplay(holder);
}else{
new MyThread(this).start();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mediaPlayer.reset();//重置后关闭音乐
}