第二个必须为框架中自定义的MyRelativeLayout,用于封装内容部分的显示
3、代码中获取DragLayout对象
4、过DragLayout对象设置监听事件DragListener
5、可以DragListener的监听中更改内容页图标的透明度等变化
如需通过代码控制菜单的打开和关闭:
dl.open(true); //打开菜单,参数代表打开过程中有动画效果
dl.close(); // 关闭菜单
package
com.wang.main;
import
android.os.Bundle;
import
android.support.v7.app.AppCompatActivity;
import
android.view.View;
import
android.view.animation.Animation;
import
android.view.animation.AnimationUtils;
import
android.widget.ImageView;
import
android.widget.LinearLayout;
import
android.widget.ScrollView;
import
android.widget.TextView;
import
android.widget.Toast;
import
com.bluemor.reddotface.view.DragLayout;
import
com.bluemor.reddotface.view.MyRelativeLayout;
import
com.nineoldandroids.view.ViewHelper;
public
class
MainActivity
extends
AppCompatActivity
implements
View.OnClickListener {
private
DragLayout dragLayout;
private
MyRelativeLayout myRelativeLayout;
private
ImageView content_iv,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);
initView();
//设置监听事件,如果不设置此事件,侧滑时没有缩放效果
dragLayout.setDragListener(
new
DragLayout.DragListener() {
@Override
public
void
onOpen() {
}
@Override
public
void
onClose() {
}
@Override
public
void
onDrag(
float
percent) {
// 可以根据滚动情况设置动画
ViewHelper.setAlpha(content_iv,
1
- percent);
Animation an= AnimationUtils.loadAnimation(MainActivity.
this
,R.anim.shake);
iv.startAnimation(an);
}
});
}
/**
* 寻找控件
*
*@author WangShujie
*created at 2016/4/23 18:59
*/
private
void
initView() {
iv= (ImageView)findViewById(R.id.slidingleft_iv);
layout1= (LinearLayout) findViewById(R.id.slidingleft_layout1);
layout2=(LinearLayout)findViewById(R.id.slidingleft_layout2);
layout3=(LinearLayout) findViewById(R.id.slidingleft_layout3);
bottom_tv1= (TextView) findViewById(R.id.sliding_botomtv1);
bottom_tv2= (TextView) findViewById(R.id.sliding_botomtv2);
scrollview= (ScrollView)findViewById(R.id.slidingleft_lv);
dragLayout= (DragLayout) findViewById(R.id.draglayout);
content_iv= (ImageView) findViewById(R.id.content_iv);
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
;
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------
布局例子
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
com.bluemor.reddotface.view.DragLayout
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:id
=
"@+id/draglayout"
android:background
=
"#000000"
>
<!--在DragLayout的标签之间添加2个子标签,第一个必须为RelativeLayout,用于封装菜单部分的显示,-->
<!--第二个必须为框架中自定义的MyRelativeLayout,用于封装内容部分的显示,有些代码拷贝的是Sliding中的,意思意思-->
<
RelativeLayout
android:id
=
"@+id/rl"
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
android:background
=
"#cf02022b"
>
</
RelativeLayout
>
<
com.bluemor.reddotface.view.MyRelativeLayout
android:layout_width
=
"match_parent"
android:layout_height
=
"match_parent"
android:id
=
"@+id/myrl"
android:background
=
"#0000ff"
>
</
com.bluemor.reddotface.view.MyRelativeLayout
>
</
com.bluemor.reddotface.view.DragLayout
>
参考代码:
http://download.csdn.net/detail/tianfuxiaoyan/9501923