android Activity实现底部滑动弹出窗口及源码下载地址

在做微信、微博、qq等分享时,一般是点击分享按钮后会从底部弹出滑动窗口,然后选择要分享的社交平台进行分享。今日头条、腾讯新闻等内容App的评论也是从底部滑动弹出输入窗口,进行评论输入的。本篇文章就讲讲怎么通过Activity实现底部弹出滑动窗口的。实现效果是通过Animation功能实现的,效果如下: 源码下载地址


主要代码如下: 

一、滑动窗口 PopupShareActivity
继承自Activity并实现了 OnClickListener,方便处理Click事件。代码如下:
public class PopupShareActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout. activity_popup_share );
//全屏Activity操作
getWindow().setLayout(WindowManager.LayoutParams. FILL_PARENT , WindowManager.LayoutParams. FILL_PARENT );
//QQ分享按钮
ImageBtn MyIBtn1 = (ImageBtn)findViewById(R.id. MyIBtn_1 );
MyIBtn1.setImageResource(R.drawable. ic_share_qq );
MyIBtn1.setText( "QQ" );

ImageBtn MyIBtn2 = (ImageBtn)findViewById(R.id. MyIBtn_2 );
MyIBtn2.setImageResource(R.drawable. ic_share_sina );
MyIBtn2.setText( "微博" );
ImageBtn MyIBtn3 = (ImageBtn)findViewById(R.id. MyIBtn_3 );
MyIBtn3.setImageResource(R.drawable. ic_share_wechat );
MyIBtn3.setText( "微信" );
ImageBtn MyIBtn4 = (ImageBtn)findViewById(R.id. MyIBtn_4 );
MyIBtn4.setImageResource(R.drawable. ic_share_wxcircle );
MyIBtn4.setText( "朋友圈" );
Button btn_cancel = (Button) this .findViewById(R.id. btn_cancel );
btn_cancel.setOnClickListener( this );
}
@Override
public void onClick(View view) {
switch (view.getId()) {

case R.id. btn_cancel :
break ;
default :
break ;
}
finish();
}

}

二、分享类布局

<? xml version= "1.0" encoding= "utf-8" ?>
< RelativeLayout xmlns: android = " http://schemas.android.com/apk/res/android" ;
android :layout_width= "fill_parent"
android :layout_height= "wrap_content"
android :gravity= "center_horizontal"
android :orientation= "vertical" >
< LinearLayout
android :id= "@+id/pop_layout"
android :layout_width= "fill_parent"
android :layout_height= "wrap_content"
android :gravity= "center_horizontal"
android :orientation= "vertical"
android :layout_alignParentBottom= "true"
android :background= "@color/color_white"
>
< LinearLayout
android :id= "@+id/share_layout"
android :layout_width= "fill_parent"
android :layout_height= "wrap_content"

android :orientation= "horizontal"
android :layout_alignParentBottom= "true"
android :background= "@color/color_white"
>

< com.jxkj.bbccode.anxiuyunslid.component.ImageBtn
android :id= "@+id/MyIBtn_1"

android :layout_height= "wrap_content"
android :layout_width= "0dp"
android :layout_weight= "1.0"

android :clickable= "true"
android :focusable= "true"
/>
< com.jxkj.bbccode.anxiuyunslid.component.ImageBtn
android :id= "@+id/MyIBtn_2"
android :layout_width= "0dp"
android :layout_weight= "1.0"
android :layout_height= "wrap_content"

android :clickable= "true"
android :focusable= "true"
/>
< com.jxkj.bbccode.anxiuyunslid.component.ImageBtn
android :id= "@+id/MyIBtn_3"
android :layout_width= "0dp"
android :layout_weight= "1.0"
android :layout_height= "wrap_content"

android :clickable= "true"
android :focusable= "true"
/>
< com.jxkj.bbccode.anxiuyunslid.component.ImageBtn
android :id= "@+id/MyIBtn_4"
android :layout_width= "0dp"
android :layout_weight= "1.0"
android :layout_height= "wrap_content"

android :clickable= "true"
android :focusable= "true"
/>
</ LinearLayout >
< Button
android :id= "@+id/btn_cancel"
android :layout_marginLeft= "20dip"
android :layout_marginRight= "20dip"
android :layout_marginTop= "15dip"
android :layout_marginBottom= "15dip"
android :layout_width= "fill_parent"
android :layout_height= "wrap_content"
android :text= "取消"

android :textColor= "#ffffff"
android :textStyle= "bold"

/>
</ LinearLayout >
</ RelativeLayout >
三、AndroidManifest添加Activity配置
< activity android :name= ".activity.PopupShareActivity"
android :theme= "@style/PopupShareActivity" >

四、 PopupShareActivity主题

< style name= "MyDialogStyleBottom" parent= "Theme.AppCompat.Light.NoActionBar" >
< item name= "android:windowAnimationStyle" >@style/AnimBottom</ item >
< item name= "android:windowFrame" >@null</ item >
<!-- 边框 -->
< item name= "android:windowIsFloating" >true</ item >
<!-- 是否浮现在activity之上 -->
< item name= "android:windowIsTranslucent" >true</ item >
<!-- 半透明 -->
< item name= "android:windowNoTitle" >true</ item >
<!-- 无标题 -->
< item name= "android:windowBackground" >@android:color/transparent</ item >
<!-- 背景透明 -->
< item name= "android:backgroundDimEnabled" >true</ item >
<!-- 模糊 -->
</ style >
< style name= "AnimBottom" parent= "@android:style/Animation" >
< item name= "android:windowEnterAnimation" >@anim/push_bottom_in</ item >
< item name= "android:windowExitAnimation" >@anim/push_bottom_out</ item >
</ style >

五、 Animation动画效果
在anim目下下定义xml文件分别为:
<!-- 上下滑入式 -->
< set xmlns: android = " http://schemas.android.com/apk/res/android" ; >

< translate
android :duration= "200"
android :fromYDelta= "100%p"
android :toYDelta= "0"
/>

</ set >

<? xml version= "1.0" encoding= "utf-8" ?>
<!-- 上下滑出式 -->
< set xmlns: android = " http://schemas.android.com/apk/res/android" ; >

< translate
android :duration= "200"
android :fromYDelta= "0"
android :toYDelta= "50%p" />
</ set >


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凡梦_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值