今天上班做那个相似于ios拍照的那种效果图 就是个垂直布局然后里面textview+切割线+textview+button

当然也能够用button+切割线+button

方法有非常多,选择适合自己的即可。

1、首先看下何为bottomsheetdialog,曾经Bottom Sheet是在support library 23.2之后提供的一个新控件。也就是须要用6.0以上的SDK进行编译才干够使用此控件

以下看下我当前的sdk版本是25因此使用全然没问题

2、看下我之前的布局

代码例如以下:

<?

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/transparent"
android:orientation="vertical"
android:gravity="bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
android:background="@drawable/round_corner"
android:orientation="vertical"
>
<TextView
android:id="@+id/tv_take_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:clickable="true"
android:background="@drawable/round_corner"
android:textColor="#cd0000"
android:text="拍照"/>
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ddd"
/>
<TextView
android:id="@+id/tv_picture_choose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center"
android:background="@drawable/round_corner"
android:textColor="#0174E1"
android:text="从相冊中选择"/>
</LinearLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:padding="1dp">
<Button
android:id="@+id/btn_cancle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
android:textColor="#0174E1"
android:layout_marginBottom="10dp"
android:background="@drawable/round_corner"
android:text="取消" />
</RelativeLayout>
</LinearLayout>

效果例如以下

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMTU5NTAzMjU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描写叙述" title="">

这不是我想要的。然后看下UI给我的原型图

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMTU5NTAzMjU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="这里写图片描写叙述" title="">

我去这不是想要的,为什么会出现这种情况,是不是设置margin的原因,好吧。那我找一下,好像不是啊!然后看到自己在这里设置了背景为半透明把这个去掉试试

好像并没什么卵用。这究竟是什么鬼,今天上班眼镜也没有戴,感觉真的像个瞎子一样!

晕!

那么继续找,问题出现了肯定要解决,最后找到了原来我在最外面那个线性布局设置了一个pading=8dp好吧我真是对自己感到失望,这技术能够退出android界了,玩不下去了!

然后把它设置为0dp试试!然后有个网友说设置0dp跟没设置一样,看看究竟是不是一样?我们一试便知晓。



这里不设置pading=0dp试试!

效果图

大家应该看到了肯定不行的

再看下我的背景round_corner.xml 代码例如以下

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#ffffff" />
<padding android:bottom="10dp"
android:left="10dp" android:right="10dp" android:top="10dp"/>
</shape>

当设置为pading=0dp时候

看效果

完美显示

看下我显示dialog的代码

private void showBottomDialog() {
final Dialog dialog = new Dialog(this, R.style.NormalDialogStyle);
View view = View.inflate(this, R.layout.activity_popwind, null);
dialog.setContentView(view);
dialog.setCanceledOnTouchOutside(true);
view.setMinimumHeight((int) (ScreenSizeUtils.getInstance(this).getScreenHeight() * 0.23f));
Window dialogWindow = dialog.getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
lp.width = (int) (ScreenSizeUtils.getInstance(this).getScreenWidth() * 0.9f);
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
dialogWindow.setAttributes(lp);
dialog.show();
final TextView takepicture = (TextView) view.findViewById(R.id.tv_take_photo);
final TextView choosePicture = (TextView) view.findViewById(R.id.tv_picture_choose);
final Button cancel = (Button) view.findViewById(R.id.btn_cancle);
/**
* 拍照
*/
takepicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
takePic();
}
});
//选择照片
choosePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
choosePic();
}
});
//取消
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//dialog.dismiss();
dialog.cancel(); }
});
}

从相冊选择照片上传并设置到ImageView显示

public void choosePic() {
Intent openAlbumIntent = new Intent(
Intent.ACTION_GET_CONTENT);
openAlbumIntent.setType("image/*");
startActivityForResult(openAlbumIntent, CHOOSE_PICTURE); }

裁剪图片简单实现

/**
* 裁剪图片方法实现
*
* @param uri
*/
protected void startPhotoZoom(Uri uri) {
if (uri == null) {
Log.i("tag", "The uri is not exist.");
}
tempUri = uri;
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
// 设置裁剪
intent.putExtra("crop", "true");
// aspectX aspectY 是宽高的比例
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
// outputX outputY 是裁剪图片宽高
intent.putExtra("outputX", 150);
intent.putExtra("outputY", 150);
intent.putExtra("return-data", true);
startActivityForResult(intent, CROP_SMALL_PICTURE);
}

图片上传至server

 private void uploadPic(Bitmap bitmap) {
// 上传至server
// 能够在这里把Bitmap转换成file,然后得到file的url,做文件上传操作
// 注意这里得到的图片已经是圆形图片了
// bitmap是没有做个圆形处理的,但已经被裁剪了 String imagePath = Utils.savePhoto(bitmap, Environment
.getExternalStorageDirectory().getAbsolutePath(), String
.valueOf(System.currentTimeMillis()));
Log.e("imagePath", imagePath + "");
if (imagePath != null) {
// 拿着imagePath上传
}
}

回调依据不同的resultCode分别进行处理

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) {
switch (requestCode) {
case TAKE_PICTURE:
startPhotoZoom(tempUri);// 開始对图片进行裁剪处理
break;
case CHOOSE_PICTURE:
startPhotoZoom(data.getData()); // 開始对图片进行裁剪处理
break;
case CROP_SMALL_PICTURE:
if (data != null) {
setImageToView(data); // 让刚才选择裁剪得到的图片显示在界面上
}
break;
default:
break;
}
}
}

总结:

1、由于自己菜

2、由于自己粗心

3、由于自己实在是菜

转载请注明出处!

http://blog.csdn.net/qq_15950325/article/details/70213684

补充:

package com.visoport.medicine.util;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager; /**
* 屏幕尺寸工具类
*/ public class ScreenSizeUtils {
private static ScreenSizeUtils instance = null;
private int screenWidth, screenHeight; public static ScreenSizeUtils getInstance (Context mContext) {
if (instance == null) {
synchronized (ScreenSizeUtils.class) {
if (instance == null)
instance = new ScreenSizeUtils(mContext);
}
}
return instance;
} private ScreenSizeUtils (Context mContext) {
WindowManager manager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(dm);
screenWidth = dm.widthPixels;// 获取屏幕分辨率宽度
screenHeight = dm.heightPixels;// 获取屏幕分辨率高度
} //获取屏幕宽度
public int getScreenWidth() {
return screenWidth;
} //获取屏幕高度
public int getScreenHeight() {
return screenHeight;
}
}

另外一种解决方式:设置顶部跟底部的圆角

<?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="@android:color/transparent"
android:orientation="vertical"> <Button
android:id="@+id/take_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/half_round_corner"
android:text="拍照" /> <TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ddd" /> <Button
android:id="@+id/picture_choose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/round_corner2"
android:text="相冊" /> <Button
android:id="@+id/btn_cancel3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/round_corner"
android:text="取消" /> <View
android:layout_width="match_parent"
android:layout_height="15dp" />
</LinearLayout>

顶部圆角

<?xml version="1.0" encoding="utf-8"?

>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
<solid android:color="#ffffff" />
<padding android:bottom="10dp"
android:left="10dp" android:right="10dp" android:top="10dp"/> <!-- 矩形的边框的宽度,每段虚线的长度,和两段虚线之间的颜色和颜色 -->
<!--<stroke-->
<!--android:width="1dp"-->
<!--android:color="#4eb621"-->
<!--android:dashGap="4dp"-->
<!--android:dashWidth="8dp" />-->` </shape>

底部圆角

<?xml version="1.0" encoding="utf-8"?

>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"/>
<solid android:color="#ffffff"/>
<padding android:bottom="10dp"
android:left="10dp" android:right="10dp" android:top="10dp"/>
<!-- 矩形的边框的宽度,每段虚线的长度。和两段虚线之间的颜色和颜色 -->
<!--<stroke-->
<!--android:width="1dp"-->
<!--android:color="#4eb621"-->
<!--android:dashGap="4dp"-->
<!--android:dashWidth="8dp" />--> </shape>

效果图例如以下

Android 关于BottomDialogSheet 与Layout擦出爱的火花?的更多相关文章

  1. [置顶] Android 关于BottomDialogSheet 与Layout擦出爱的火花?

    今天上班做那个类似于ios拍照的那种效果图 就是个垂直布局然后里面textview+分割线+textview+button 当然也可以用button+分割线+button 方法有很多,选择适合自己的就 ...

  2. 小程序与WebRTC联姻能擦出怎样的火花?

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯视频云终端团队发表于云+社区专栏 腾讯视频云终端技术总监,rexchang(常青), 2008 年毕业加入腾讯,一直从事客户端研发 ...

  3. 当Spring Cloud Alibaba Sentinel碰上Spring Cloud Sleuth会擦出怎样的火花

    前言 今年主要会做一个比较完整的微服务项目开源出来.目前已经开始了,刚兴趣的先Star一个吧. 项目:https://github.com/yinjihuan/kitty-cloud 基础框架:htt ...

  4. 当 SQL DELETE 邂逅 Table aliases,会擦出怎样的火花

    开心一刻 晚上,女儿眼噙泪水躺在床上 女儿:你口口声声说爱我,说陪我,却天天想着骗我零花钱,你是我亲爹吗? 我:你想知道真相 女儿:想! 我:那你先给爸爸两百块钱! 环境准备 MySQL 不同版本 利 ...

  5. Android帧布局(Frame Layout)

    Android帧布局(Frame Layout) FrameLayout是最简单的一个布局管理器.FrameLayout为每个加入其中的组件创建一个空白区域(一帧),这些组件根据layout_grav ...

  6. Android 高仿QQ滑动弹出菜单标记已读、未读消息

    在上一篇博客<Android 高仿微信(QQ)滑动弹出编辑.删除菜单效果,增加下拉刷新功能>里,已经带着大家学习如何使用SwipeMenuListView这一开源库实现滑动列表弹出菜单,接 ...

  7. Android View框架的layout机制

    概述 Android中View框架的工作机制中,主要有三个过程: 1.View树的测量(measure) Android View框架的measure机制 2.View树的布局(layout)Andr ...

  8. [转]【android studio】解决layout预览出现Rendering Problems Exception Unable to find the layout for Action Bar.

    在android studio中打开layout文件,发现不能预览布局,提示以下错误: Rendering Problems Exception raised during rendering: Un ...

  9. Android线性布局(Linear Layout)

    Android线性布局(Linear Layout) LinearLayout是一个view组(view group),其包含的所有子view都以一个方向排列,垂直或是水平方向.我们能够用androi ...

随机推荐

  1. 【01】markdown特殊说明

    [01]说明 Markdown 的目标是实现「易读易写」. 可读性,无论如何,都是最重要的.一份使用 Markdown 格式撰写的文件应该可以直接以纯文本发布,并且看起来不会像是由许多标签或是格式指令 ...

  2. 关于面试总结-python笔试题

    关于面试总结4-python笔试题 前言 现在面试测试岗位,一般会要求熟悉一门语言(python/java),为了考验求职者的基本功,一般会出2个笔试题,这些题目一般不难,主要考察基本功. 要是给你一 ...

  3. 【java基础 7】java内存区域分析及常见异常

    本篇博客,主要是读书笔记总结,还有就是结合培训分享的总结,没有太多的技术含量! java 的自动内存管理机制,使得程序员不用为每一个new惭怍的对象写配对的delete/ free代码(回想起C++的 ...

  4. 更新yum源导致yum不可用

    当安装和yum配置相关的包后报yum模块找不到 yum install -y yum-utils device-mapper-persistent-data lvm2 yum list|grep yu ...

  5. 最近项目中公用的JS

    var closeid = 1; var isneedpwd = 0; var editor1; var NoCheckUrl = 0;//适用于框架 不验证权限 !=0验证 function Erp ...

  6. 性能测试之五--webservices接口测试

    下面我们进行webservices接口的讲解,包括脚本生成,参数化和关联. 以天气预报的接口为例,接口地址为: http://ws.webxml.com.cn/WebServices/WeatherW ...

  7. 将SSM架构中原来关于springSecurity3.x版本的写法配迁移到SpringBoot2.0框架中出现的问题解决记

    迁移过程中关于这个安全框架的问题很麻烦,springBoot自带的stater中的版本是5.0,原来系统有通过实现"org.springframework.security.authenti ...

  8. 【bzoj4004】【JLOI2015】装备购买 (线性基+高斯消元)

    Description 脸哥最近在玩一款神奇的游戏,这个游戏里有 n 件装备,每件装备有 m 个属性,用向量zi(aj ,.....,am) 表示 (1 <= i <= n; 1 < ...

  9. indexedDB 增删改查

    /** * 打开数据库 */ export function openDB() { return new Promise((resolve, reject) => { let indexedDB ...

  10. shell的case脚本的简单入门

    shell的case脚本的简单入门 示例1: #/bin/bash a=$ case "$a" in ") echo 'hell 2';; ") echo 'h ...