[置顶] Android 关于BottomDialogSheet 与Layout擦出爱的火花?
今天上班做那个类似于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>
效果如下
这不是我想要的,然后看下UI给我的原型图
我去这不是想要的,为什么会出现这样的情况,是不是设置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);
}
图片上传至服务器
private void uploadPic(Bitmap bitmap) {
// 上传至服务器
// 可以在这里把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擦出爱的火花?的更多相关文章
- Android 关于BottomDialogSheet 与Layout擦出爱的火花?
今天上班做那个相似于ios拍照的那种效果图 就是个垂直布局然后里面textview+切割线+textview+button 当然也能够用button+切割线+button 方法有非常多,选择适合自己的 ...
- [置顶] Android开发笔记(成长轨迹)
分类: 开发学习笔记2013-06-21 09:44 26043人阅读 评论(5) 收藏 Android开发笔记 1.控制台输出:called unimplemented OpenGL ES API ...
- [置顶]
Android开发百科全书
友情提示根据目录 快速查找问题 %1$s %1$d Android string 1.整型,比如"我今年23岁了",这个23是整型的.在string.xml中可以这样写,<s ...
- [置顶]
Android RadioButton与TextView浪漫约会?
情景一 今天主要实现一个国家与地区切换,就是当我们选中RadioButton时然后将值设置到TextView中,听着这需求应该不难对吧?那么我们就开始约会吧? 看下原型图 准备条件: 首先需要一个ra ...
- [置顶] Android系统五大布局详解Layout
我们知道Android系统应用程序一般是由多个Activity组成,而这些Activity以视图的形式展现在我们面前,视图都是由一个一个的组件构成的.组件就是我们常见的Button.TextEdit等 ...
- [置顶] Android AlarmManager实现不间断轮询服务
在消息的获取上是选择轮询还是推送得根据实际的业务需要来技术选型,例如对消息实时性比较高的需求,比如微博新通知或新闻等那就最好是用推送了.但如果只是一般的消息检测比如更新检查,可能是半个小时或一个小时一 ...
- [置顶] android利用jni调用第三方库——第三篇——编写库android程序整合第三方库libhello.so到自己的库libhelloword.so
0:前言: 在第二篇中,我们主要介绍了丙方android公司利用乙方C++公司给的动态库,直接调用库中的方法,但是这样方式受限于: 乙方C++公司开发的动态库是否符合jni的规范,如果不规范,则不能直 ...
- [置顶]
Android 适配真要命?
原始尺寸场景 相信大家对上面也有所有耳闻另外就是如何计算屏幕的密度一般都是按照勾股定理例如中等屏幕密度 480^2+800^2开根号 然后除以当前屏幕尺寸3.5-4.2之间尺寸. 对于刚出来的那些An ...
- [置顶] Android应用开发之版本更新你莫愁
传送门 ☞ 轮子的专栏 ☞ 转载请注明 ☞ http://blog.csdn.net/leverage_1229 今天我们学习如何实现Android应用的自动更新版本功能,这是在各种语言编写的应用中都 ...
随机推荐
- 经典iOS第三方库源码分析 - YYModel
YYModel介绍 YYModel是一个针对iOS/OSX平台的高性能的Model解析库,是属于YYKit的一个组件,创建是ibireme. 其实在YYModel出现之前,已经有非常多的Model解析 ...
- python入门三:文件操作
一.文件操作 1.文件对象:和c一样,要想对一个文件进行操作,需要获取该文件的对象 f = open("xxx") # 打开文件并获取文件对象 f.xxx # 对文件进行某些操作 ...
- Linux负载均衡--LVS(IPVS)
一.LVS简介 LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起的自由软件项目,现在已经是 Linux标准内核的一部分.LVS是一种叫基于T ...
- SpringBoot 事务隔离性和传播性
propergation 传播性 Spring中七种Propagation类的事务属性详解: REQUIRED:支持当前事务,如果当前没有事务,就新建一个事务.这是最常见的选择. SUPPORTS ...
- linux 挂在新硬盘
记录一下 全忘了..... PS 测试服务器的主板太差劲了,没有多余的电源接口,只能把光驱的电源拿出来,才能让硬盘使用.把硬盘装好后,我们用 fdisk -l 查看下: 图中可以看出 /dev/ ...
- php异常处理笔记
<?php header("Content-type:text/html;charset=utf-8"); // try // { // //业务处理 错误时抛出异常. // ...
- JAVA集合类汇总 - 转载
一.集合与数组 数组(可以存储基本数据类型)是用来存现对象的一种容器,但是数组的长度固定,不适合在对象数量未知的情况下使用. 集合(只能存储对象,对象类型可以不一样)的长度可变,可在多数情况下使用. ...
- C语言之非常简单的几道题
C语言之非常简单的几道题(还是写写),比较简单吧,主要有几道题的数据类型(如,第三题)和语句顺序(如,第二题)需要注意一小下下. 1. 求表达式S=1*2*3……*N的值大于150时,最小的N的值 / ...
- JNI_Z_03_类中的字段和方法的签名
1. Java类型 相应的签名 例子 boolean Z byte B char C short S int I long L float F double D void V Object L用&qu ...
- 从TensorFlow 到 Caffe2:盘点深度学习框架
机器之心报道 本文首先介绍GitHub中最受欢迎的开源深度学习框架排名,然后再对其进行系统地对比 下图总结了在GitHub中最受欢迎的开源深度学习框架排名,该排名是基于各大框架在GitHub里的收藏数 ...