用PopWindow仿iOS照片上传的dialog
来源:互联网 发布:消防联动编程规范 编辑:程序博客网 时间:2024/06/06 07:16
很多时候 产品经理要求Android 要照着iOS,本人写了一个仿iOS的照片上传,
如有问题可以与本菜鸟联系 QQ:2428566234技术讨论群:387648673
public class MainActivity extends FragmentActivity implements View.OnClickListener {
private TextView takePhotosTv;
private PopupWindow popWindow;
private TextView takePicturesTv,cameraTv,cancleTv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
takePhotosTv =(TextView) findViewById(R.id.tv_main_takephotos);
takePhotosTv.setOnClickListener(this);
}
private void showPopWindow() {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.pupwindow, null);
popWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
popWindow.setFocusable(true);
//设置popWindow可点击
popWindow.setTouchable(true);
//为popWindow设置背景
ColorDrawable cd = new ColorDrawable(Color.parseColor("#FFFFFFFF"));
popWindow.setBackgroundDrawable(cd);
popWindow.setAnimationStyle(R.style.AnimBottom);
popWindow.showAtLocation(takePhotosTv, Gravity.BOTTOM,0,0);
takePicturesTv = (TextView) view.findViewById(R.id.tv_takepictures);
cameraTv = (TextView) view.findViewById(R.id.tv_camera);
cancleTv = (TextView) view.findViewById(R.id.tv_cancle);
takePicturesTv.setOnClickListener(this);
cameraTv.setOnClickListener(this);
cancleTv.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.tv_main_takephotos:
showPopWindow();
break;
case R.id.tv_takepictures:
Toast.makeText(MainActivity.this,"拍照",Toast.LENGTH_SHORT).show();
break;
case R.id.tv_camera:
Toast.makeText(MainActivity.this,"相册",Toast.LENGTH_SHORT).show();
break;
case R.id.tv_cancle:
popWindow.dismiss();
Toast.makeText(MainActivity.this,"取消",Toast.LENGTH_LONG).show();
break;
}
}
}
看看布局 activity_main
<RelativeLayout 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">
<TextView
android:id="@+id/tv_main_takephotos"
android:text="上传照片"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:textSize="22sp"
android:gravity="center"
android:layout_height="50dp" />
</RelativeLayout>
pupwindow.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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70.5dp"
android:layout_margin="5dp"
android:background="@drawable/dialog_white_bg"
android:orientation="vertical">
<TextView
android:id="@+id/tv_camera"
android:layout_width="match_parent"
android:layout_height="35dp"
android:gravity="center"
android:text="相册"
android:textSize="17sp" />
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#cccccc">
</View>
<TextView
android:id="@+id/tv_takepictures"
android:layout_width="match_parent"
android:layout_height="35dp"
android:gravity="center"
android:text="拍照"
android:textSize="17sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_cancle"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_margin="5dp"
android:layout_marginTop="10dp"
android:background="@drawable/dialog_white_bg"
android:gravity="center"
android:text="取消"
android:textSize="17sp" />
</LinearLayout>
Style 文件
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> </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></resources>
动画效果在res 新建anim 文件
新建push_bottom_in push_bottom_out 都是以下文件
<?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" />
<alpha
android:duration="200"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>
拍照的背景drawable 文件
dialog_white_bg.xml代码如下<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape>
<!-- 描边 -->
<stroke android:width="0.5dp" android:color="#cccccc" />
<solid android:color="#ffffff" />
<!-- 圆角 -->
<corners android:radius="6dp" />
</shape></item>
<item android:state_focused="true"><shape>
<!-- 描边 -->
<stroke android:width="0.5dp" android:color="#cccccc" />
<solid android:color="#ffffff" />
<!-- 圆角 -->
<corners android:radius="6dp" />
</shape></item>
<item><shape>
<!-- 描边 -->
<stroke android:width="0.5dp" android:color="#cccccc" />
<solid android:color="#ffffff" />
<!-- 圆角 -->
<corners android:radius="6dp" />
</shape></item>
</selector>
- 用PopWindow仿iOS照片上传的dialog
- 仿IOS的dialog
- 类似popwindow的dialog
- Android自定义Dialog仿IOS的Dialog
- 各种Popwindow和Dialog的汇总以及仿ios的,可以自定义布局,也可以傻瓜式的代码生成,使用非常方便
- 用自定义布局实现仿IOS的dialog布局
- popwindow和dialog的区别
- android 仿 微信带尖角的popwindow
- Android仿iOS样式的dialog
- 仿iOS弹出Dialog
- 仿ios风格dialog
- 基于ueditor开发的仿QQ空间照片上传功能
- iOS 上传照片到服务器 获取相册和拍照功能的照片 照片压缩上传
- iOS上传照片
- android popwindow和dialog的取舍
- 自定义Dialog实现popwindow的效果
- iOS 上传视频 ,上传照片
- 仿IPhone、ios圆角Dialog
- YTU 2916: Shape系列-2
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- input标签/复选框/单选框点击文字有效果
- iTOP-4412开发板Android操作系统源码编译过程全纪录
- c++ + opencv + linux下加载文件(图片或级联分类器)路径的问题
- 用PopWindow仿iOS照片上传的dialog
- Android Studio 9n图片相关问题
- SSL连接建立过程分析(1)
- 使用JS实现导出功能1
- 如何学习Unity3d开发,菜鸟在线有妙招!
- Notepad++设置运行Python程序
- Amazon的推荐系统
- poj-2485-最小生成树prim算法模板
- phpcms v9 表单向导 在线留言后,发送邮件(含留言内容)