Android Dialog实现缩放动画并且是自定义Dialog,4角是圆角

本文介绍了如何在Android中创建一个带有圆角的自定义Dialog,并实现缩放动画效果。通过动态布局和特定的设置,使得Dialog的四个角呈现圆润效果,同时加入了缩放动画,提升用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
View inflate = LayoutInflater.from(context).inflate(R.layout.caiming, null);
EditText editText = (EditText) inflate.findViewById(R.id.editText);
editText.setText(list.get(position).getName());
Button button = (Button) inflate.findViewById(R.id.button);
Dialog dialog = new AlertDialog.Builder(context).setView(inflate).show();
dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialogyuanjiao);
Animation animation = AnimationUtils.loadAnimation(context, R.anim.scale);
inflate.setAnimation(animation);
animation.start();

动态布局

 
<?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"
    android:padding="20dp">

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="50dp"
        android:background="@drawable/bgk_yj"
        android:text="啤酒" />

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="30dp"
        android:background="@drawable/yj"
        android:text="@string/ConfirmText"
        android:textColor="@color/white" />
</LinearLayout>

//4个角圆角设置

 
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="8dp" />
</shape>

//缩放动画

 
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android">

    <scale
        android:duration="1000"
        android:fromXScale="0"
        android:fromYScale="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="100%"
        android:toYScale="100%" />
</scale>
注意:4个角和自定义布局里的背景设置圆角也是有关系的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值