android popup阴影布局

该代码示例展示了一个Android应用,使用VideoView播放网络视频,并在点击按钮后弹出一个PopupWindow,显示四个可点击的TextView,每个TextView对应不同的倍速选项。用户选择倍速后,PopupWindow关闭,视频切换至所选速度。
摘要由CSDN通过智能技术生成

 

public class MainActivity extends AppCompatActivity {

    private VideoView videoView;
    private PopupWindow pw;
    private View viewById;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        videoView = findViewById(R.id.player);
        viewById = findViewById(R.id.view);
        videoView.setUrl("https://mysdev.obs.cn-east-2.myhuaweicloud.com:443/video/2022/12/22/e290b6640387a1c149f504013895bbed.mp4"); //设置视频地址
        StandardVideoController controller = new StandardVideoController(this);
        controller.addDefaultControlComponent("标题", false);
        videoView.setVideoController(controller); //设置控制器
        videoView.start(); //开始播放,不调用则不自动播放
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showEditPhotoWindow();
            }
        });
    }


    private void showEditPhotoWindow() {
        View contentView = getLayoutInflater().inflate(R.layout.my_pop, null,false);
        pw = new PopupWindow(contentView, getWindowManager().getDefaultDisplay().getWidth(), dip2px(this,300), true);
        pw.setBackgroundDrawable(new ColorDrawable());
        pw.showAsDropDown(viewById);
        initView(contentView);
    }

    private void initView(View contentView) {
        TextView tv1 = contentView.find
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
WPF中的Popup控件是一个常用的容器控件,在实现各种功能时经常用到。而对于Popup控件的阴影设置,可以通过以下几种方式实现: 1. 使用DropShadowEffect WPF中可以通过DropShadowEffect效果给控件添加阴影,可以使用以下代码将阴影效果添加到Popup控件中: ``` <Popup Name="MyPopup" Width="300" Height="250"> <Border Background="White" BorderThickness="2" BorderBrush="Gray"> <Border.Effect> <DropShadowEffect Color="Gray" BlurRadius="15" Opacity=".75" ShadowDepth="5" /> </Border.Effect> <!-- 添加Popup控件内容 --> </Border> </Popup> ``` 2. 添加阴影Border 除了使用DropShadowEffect效果,还可以通过在Popup控件外部添加一个带阴影的Border元素来实现阴影效果。以下是示例代码: ``` <Border Background="Transparent" BorderThickness="0"> <Border Background="White" BorderThickness="2" BorderBrush="Gray"> <Popup Name="MyPopup" Width="300" Height="250"> <!-- 添加Popup控件内容 --> </Popup> </Border> <Border.Effect> <DropShadowEffect Color="Gray" BlurRadius="15" Opacity=".75" ShadowDepth="5" /> </Border.Effect> </Border> ``` 3. 使用VisualBrush 还可以通过使用VisualBrush将Popup控件的内容绘制到Canvas上,并在Canvas上添加阴影效果来实现。以下是示例代码: ``` <Popup Name="MyPopup" Width="300" Height="250"> <!-- 定义VisualBrush --> <Popup.Resources> <VisualBrush x:Key="PopupContent"> <VisualBrush.Visual> <ContentControl Content="{Binding ElementName=MyPopup, Path=Child}"/> </VisualBrush.Visual> </VisualBrush> </Popup.Resources> <Canvas> <!-- 绘制Popup内容 --> <Rectangle Fill="{StaticResource PopupContent}" Width="{Binding ActualWidth, ElementName=MyPopup}" Height="{Binding ActualHeight, ElementName=MyPopup}" /> <!-- 添加阴影效果 --> <Rectangle Fill="Gray" Opacity="0.5" Width="{Binding ActualWidth, ElementName=MyPopup}" Height="{Binding ActualHeight, ElementName=MyPopup}"> <Rectangle.Effect> <DropShadowEffect BlurRadius="15" Opacity=".75" ShadowDepth="5" Direction="-90" /> </Rectangle.Effect> </Rectangle> </Canvas> </Popup> ``` 通过以上几种方式实现Popup控件的阴影效果,可以根据实际需求选择最合适的方法,从而大大提高了应用程序的用户体验。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值