PopupWindow全屏显示以及适配不同手机屏幕之 应用实例 更换头像,拍照,相册选取附带动画效果

最近找工作,所以闲余时间还是比较充足的,今晚刚好没有睡意,抽取了一个之前项目中自己写过的一个功能。更换头像,可以拍照,可以从相册选取照片,有裁剪功能。其中的一个坑是PopupWindow的显示位置以及是否全屏显示适配不同手机。
话不多少,先上效果。

这里写图片描述 这里写图片描述
因为这个效果展示时间比较长,所以分了两段录结果还是大了,把gif图片质量压缩了。
大致解释下,效果就是点击按钮弹出popupwindow,更换头像可选择拍照和相册选取,并且可以裁剪。退出程序保存的头像依然保留。

下来先看看一步一步实现
由于今天我的Android studio有点,所以这个demo我是用eclipse写的。效果都是一样的。
1.PopupWindow 首先是布局样式 activity_choose_picture.xml

<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"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dp"
        android:background="@color/btn_bottom_tv_gray"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button_take_photo"
            style="@style/txt_camera_pop_menu"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:background="@drawable/pop_first_selector"
            android:text="@string/camera_pop_camera"
            android:textSize="18sp" />

        <Button
            android:id="@+id/button_choice_photo"
            style="@style/txt_camera_pop_menu"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:background="@drawable/pop_last_selector"
            android:text="@string/camera_pop_album"
            android:textSize="18sp" />

        <Button
            android:id="@+id/button_choice_cancel"
            style="@style/txt_camera_pop_menu"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/pop_single_selector"
            android:text="@string/camera_pop_cancel"
            android:textSize="18sp" />
    </LinearLayout>

</RelativeLayout>

这个就是弹出popupwindow的布局
资源文件,style.xml这里我们要自定义样式

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
         <item name="android:windowNoTitle">true</item>
    </style>



     <style name="PopupAnimation" parent="android:Animation">
        <item name="android:windowEnterAnimation">@anim/push_bottom_in</
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值