最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 從底部彈出Dialog(橫向滿(mǎn)屏)的實(shí)例代碼

 更新時(shí)間:2016年11月22日 08:46:32   作者:掌握當(dāng)下  
在android開(kāi)發(fā)中經(jīng)常會(huì)遇到底部彈出框的功能,今天小編抽時(shí)間給大家整理一個(gè)底部彈出橫向滿(mǎn)屏的dialog,需要的朋友參考下

項(xiàng)目中經(jīng)常需要底部彈出框,這里我整理一下其中我用的比較順手的一個(gè)方式(底部彈出一個(gè)橫向滿(mǎn)屏的dialog)。

效果圖如下所示(只顯示關(guān)鍵部分):

步驟如下所示:

1.定義一個(gè)dialog的布局(lay_share.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="@dimen/padding_15"
android:paddingTop="@dimen/padding_15">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/padding_5"
android:drawableTop="@mipmap/ic_weixin_share"
android:gravity="center"
android:text="微信"
android:textColor="@color/color_999999"
android:textSize="@dimen/text_14" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/padding_5"
android:drawableTop="@mipmap/ic_circle_share"
android:gravity="center"
android:text="朋友圈"
android:textColor="@color/color_999999"
android:textSize="@dimen/text_14" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/padding_5"
android:drawableTop="@mipmap/ic_weibo_share"
android:gravity="center"
android:text="微博"
android:textColor="@color/color_999999"
android:textSize="@dimen/text_14" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="@dimen/padding_10"
android:layout_marginRight="@dimen/padding_10"
android:background="@color/color_c9c9c9" />
<TextView
android:id="@+id/tv_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/padding_15"
android:text="取消"
android:textColor="@color/color_666666"
android:textSize="@dimen/text_18" />
</LinearLayout>

2.定義彈出框彈出動(dòng)畫(huà)(dialog_enter.xml)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="100%p"
android:toYDelta="0" />
</set>
dialog_enter.xml

3.定義彈出框隱藏動(dòng)畫(huà)(dialog_exit.xml)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="300"
android:fromYDelta="0"
android:toYDelta="100%p" />
</set>
dialog_exit.xml

4.定義動(dòng)畫(huà)style

<!--彈出框動(dòng)畫(huà)-->
<style name="share_animation" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/dialog_enter</item>
<item name="android:windowExitAnimation">@anim/dialog_exit</item>
</style>

5.定義對(duì)話(huà)框樣式

<!-- 對(duì)話(huà)框樣式 -->
<style name="dialog_bottom_full" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:scrollHorizontally">true</item>
</style>

6.最后,在需要從底部彈出dialog的地方,直接調(diào)用showDialog()方法

/**
* 顯示分享彈出框
*/
private void showDialog() {
if (mShareDialog == null) {
initShareDialog();
}
mShareDialog.show();
}
/**
* 初始化分享彈出框
*/
private void initShareDialog() {
mShareDialog = new Dialog(this, R.style.dialog_bottom_full);
mShareDialog.setCanceledOnTouchOutside(true);
mShareDialog.setCancelable(true);
Window window = mShareDialog.getWindow();
window.setGravity(Gravity.BOTTOM);
window.setWindowAnimations(R.style.share_animation);
View view = View.inflate(this, R.layout.lay_share, null);
view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mShareDialog != null && mShareDialog.isShowing()) {
mShareDialog.dismiss();
}
}
});
window.setContentView(view);
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//設(shè)置橫向全屏
}

以上所述是小編給大家介紹的Android 從底部彈出Dialog(橫向滿(mǎn)屏)的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論

周至县| 肃宁县| 林甸县| 玉溪市| 晋州市| 砚山县| 乐昌市| 莱西市| 咸丰县| 宁陵县| 苏尼特左旗| 定边县| 水富县| 合肥市| 兴城市| 类乌齐县| 巴塘县| 东山县| 沈阳市| 汉阴县| 福建省| 饶阳县| 河南省| 阿合奇县| 阿图什市| 沁阳市| 吉林市| 西林县| 健康| 大连市| 彰化县| 将乐县| 德保县| 清原| 建昌县| 德阳市| 大兴区| 镇江市| 怀集县| 萨嘎县| 吴忠市|