当前位置: 首页>>代码示例>>Java>>正文


Java FrameLayout.setForeground方法代码示例

本文整理汇总了Java中android.widget.FrameLayout.setForeground方法的典型用法代码示例。如果您正苦于以下问题:Java FrameLayout.setForeground方法的具体用法?Java FrameLayout.setForeground怎么用?Java FrameLayout.setForeground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.FrameLayout的用法示例。


在下文中一共展示了FrameLayout.setForeground方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: inflateYouTubeVideo

import android.widget.FrameLayout; //导入方法依赖的package包/类
private static FrameLayout inflateYouTubeVideo(final Context context, final String videoId, boolean isFirstView, boolean isLastView) {
    final FrameLayout videoLayout = new FrameLayout(context);
    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    videoLayout.setForeground(ContextCompat.getDrawable(context, outValue.resourceId));

    final ImageView youTubeThumbnailView = new ImageView(context);
    final ImageView playLogo = new ImageView(context);
    playLogo.setVisibility(View.GONE);
    playLogo.setImageResource(R.drawable.youtube_play_logo);

    videoLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = YouTubeStandalonePlayer.createVideoIntent((Activity) context,
                    context.getString(R.string.google_dev_api_key), videoId, 0, true, true);
            if (intent.resolveActivity(context.getPackageManager()) != null)
                context.startActivity(intent);
            else
                AppmaticUtils.openPlayStore(context, "com.google.android.youtube");

        }
    });
    Glide.with(context)
            .load("https://img.youtube.com/vi/" + videoId + "/0.jpg")
            .centerCrop()
            .into(new SimpleTarget<GlideDrawable>() {
                @Override
                public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                    youTubeThumbnailView.setImageDrawable(resource);
                    playLogo.setVisibility(View.VISIBLE);
                }
            });

    youTubeThumbnailView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    LinearLayout.LayoutParams thumbnailParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            (int) context.getResources().getDimension(R.dimen.youtube_thumbnail));
    thumbnailParams.gravity = Gravity.CENTER_HORIZONTAL;
    youTubeThumbnailView.setLayoutParams(thumbnailParams);

    FrameLayout.LayoutParams playLogoParams = new FrameLayout.LayoutParams(
            (int) TypedValue.applyDimension
                    (TypedValue.COMPLEX_UNIT_DIP, 96, context.getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension
                    (TypedValue.COMPLEX_UNIT_DIP, 96, context.getResources().getDisplayMetrics()));
    playLogoParams.gravity = Gravity.CENTER;
    playLogo.setLayoutParams(playLogoParams);

    LinearLayout.LayoutParams frameLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    videoLayout.addView(youTubeThumbnailView);
    videoLayout.addView(playLogo);

    if (isFirstView && isLastView)
        videoLayout.setLayoutParams(injectFrameLayoutMargins(frameLayoutParams, 0, 0, 0, 0));
    else if (isFirstView)
        videoLayout.setLayoutParams(injectFrameLayoutMargins(frameLayoutParams, 0, 0, 0, halfMargin));
    else if (isLastView)
        videoLayout.setLayoutParams(injectFrameLayoutMargins(frameLayoutParams, 0, halfMargin, 0, 0));
    else
        videoLayout.setLayoutParams(injectFrameLayoutMargins(frameLayoutParams, 0, halfMargin, 0, halfMargin));

    return videoLayout;
}
 
开发者ID:Nulltilus,项目名称:Appmatic-Android,代码行数:67,代码来源:ViewParsingUtils.java


注:本文中的android.widget.FrameLayout.setForeground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。