本文整理汇总了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;
}