Java Code Examples for android.view.ViewGroup.addView()

The following are Jave code examples for showing how to use addView() of the android.view.ViewGroup class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: dkplayer   File: IjkVideoView.java   View Source Code Vote up 7 votes
@Override
public void startFullScreen() {
    if (mVideoController == null) return;
    Activity activity = WindowUtil.scanForActivity(mVideoController.getContext());
    if (activity == null) return;
    if (isFullScreen) return;
    WindowUtil.hideSystemBar(getContext());
    this.removeView(playerContainer);
    ViewGroup contentView = activity
            .findViewById(android.R.id.content);
    LayoutParams params = new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    contentView.addView(playerContainer, params);
    orientationEventListener.enable();
    isFullScreen = true;
    mVideoController.setPlayerState(PLAYER_FULL_SCREEN);
}
 
Example 2
Project: ScrollShapeUI   File: StatusBarUtil.java   View Source Code Vote up 6 votes
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 * @param color        状态栏颜色值
 */
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // 生成一个状态栏大小的矩形
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
            contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
        } else {
            // 添加 statusBarView 到布局中
            StatusBarView statusBarView = createStatusBarView(activity, color);
            contentLayout.addView(statusBarView, 0);
        }
        // 内容布局不是 LinearLayout 时,设置padding top
        if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        // 设置属性
        ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
        drawerLayout.setFitsSystemWindows(false);
        contentLayout.setFitsSystemWindows(false);
        contentLayout.setClipToPadding(true);
        drawer.setFitsSystemWindows(false);
    }
}
 
Example 3
Project: XinFramework   File: SwipeBackLayout.java   View Source Code Vote up 6 votes
public void attachToActivity(FragmentActivity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.windowBackground
    });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
 
Example 4
Project: Excuser   File: StatusBarUtil.java   View Source Code Vote up 6 votes
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 * @param color        状态栏颜色值
 */
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // 生成一个状态栏大小的矩形
        View statusBarView = createStatusBarView(activity, color);
        // 添加 statusBarView 到布局中
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        contentLayout.addView(statusBarView, 0);
        // 内容布局不是 LinearLayout 时,设置padding top
        if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        // 设置属性
        ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
        drawerLayout.setFitsSystemWindows(false);
        contentLayout.setFitsSystemWindows(false);
        contentLayout.setClipToPadding(true);
        drawer.setFitsSystemWindows(false);
    }
}
 
Example 5
Project: RoadLab-Pro   File: ImagePagerAdapter.java   View Source Code Vote up 6 votes
@Override
    public Object instantiateItem(ViewGroup container, final int position) {
        final ImageView imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        //RequestQueueHelper.getInstance(context).getImageLoader().displayImage(data.get(position), imageView);
        UIUtils.setImageFromLink(imageView, data.get(position));
//        if (URLUtil.isHttpsUrl(data.get(position))) {
//
//        } else {
//            final Bitmap bitmap = FileUtils.loadFileFromExternalStorage(context, data.get(position));
//            if (bitmap != null) {
//                imageView.setImageBitmap(bitmap);
//            }
//        }
        container.addView(imageView, 0);
        return imageView;
    }
 
Example 6
Project: Daejeon-People   File: MainPopularAdapter.java   View Source Code Vote up 6 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {
    // TODO Auto-generated method stub
    View view = null;
    view= inflater.inflate(R.layout.main_viewpager_popular, null);
    ImageView img= (ImageView)view.findViewById(R.id.img_viewpager_childimage);
    TextView maintext = (TextView)view.findViewById(R.id.text_viewpager_main);
    TextView subtext = (TextView)view.findViewById(R.id.text_viewpager_sub);
    Log.d("position", position+"");
    maintext.setText(mDataset.get(position).getTitle());
    subtext.setText(mDataset.get(position).getEng_title());
    Log.d("image url", mDataset.get(position).getImage());

    if(mDataset.get(position).getImage() == "NoImage"){
        Glide.with(mContext).load(R.drawable.noimage).into(img);
    } else {
        String imgUrl = mDataset.get(position).getImage().substring(1, mDataset.get(position).getImage().length() - 1);
        Log.d("image url2", imgUrl);
        Glide.with(mContext).load(imgUrl).into(img);
    }
    container.addView(view);
    return view;
}
 
Example 7
Project: Hotspot-master-devp   File: SlideAdapter.java   View Source Code Vote up 6 votes
@Override
public ImageView instantiateItem(ViewGroup container, int position) {
    ImageView imageView = (ImageView) View.inflate(mContext,R.layout.view_image, null);
    if(mDatas!=null) {
        MediaInfo mediaInfo = mDatas.get(position);
        String assetpath = mediaInfo.getAssetpath();
        if(new File(assetpath).exists()) {
            Glide.with(mContext).load(mediaInfo.getAssetpath()).
                    placeholder(R.drawable.kong_mrjz).
                    dontAnimate().
                    into(imageView);
        }else {
            Glide.with(mContext).load(R.drawable.icon_pic_unexits).
                    placeholder(R.drawable.icon_pic_unexits).
                    dontAnimate().
                    into(imageView);
        }
    }
    container.addView(imageView, 0);
    return imageView;
}
 
Example 8
Project: Edu   File: JCVideoPlayer.java   View Source Code Vote up 5 votes
public void startWindowFullscreen() {
        Log.i(TAG, "startWindowFullscreen " + " [" + this.hashCode() + "] ");
        hideSupportActionBar(getContext());
        JCUtils.getAppCompActivity(getContext()).setRequestedOrientation(FULLSCREEN_ORIENTATION);

        ViewGroup vp = (ViewGroup) (JCUtils.scanForActivity(getContext()))//.getWindow().getDecorView();
                .findViewById(Window.ID_ANDROID_CONTENT);
        View old = vp.findViewById(FULLSCREEN_ID);
        if (old != null) {
            vp.removeView(old);
        }
//        ((ViewGroup)JCMediaManager.textureView.getParent()).removeView(JCMediaManager.textureView);
        textureViewContainer.removeView(JCMediaManager.textureView);
        try {
            Constructor<JCVideoPlayer> constructor = (Constructor<JCVideoPlayer>) JCVideoPlayer.this.getClass().getConstructor(Context.class);
            JCVideoPlayer jcVideoPlayer = constructor.newInstance(getContext());
            jcVideoPlayer.setId(FULLSCREEN_ID);
            FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            vp.addView(jcVideoPlayer, lp);
            jcVideoPlayer.setUp(url, JCVideoPlayerStandard.SCREEN_WINDOW_FULLSCREEN, objects);
            jcVideoPlayer.setUiWitStateAndScreen(currentState);
            jcVideoPlayer.addTextureView();
            JCVideoPlayerManager.setSecondFloor(jcVideoPlayer);
//            final Animation ra = AnimationUtils.loadAnimation(getContext(), R.anim.start_fullscreen);
//            jcVideoPlayer.setAnimation(ra);
            CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
Example 9
Project: androidtools   File: SystemBarTintManager.java   View Source Code Vote up 5 votes
private void setupStatusBarView(Context context, ViewGroup decorViewGroup) {
    mStatusBarTintView = new View(context);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mConfig.getStatusBarHeight());
    params.gravity = Gravity.TOP;
    if (mNavBarAvailable && !mConfig.isNavigationAtBottom()) {
        params.rightMargin = mConfig.getNavigationBarWidth();
    }
    mStatusBarTintView.setLayoutParams(params);
    mStatusBarTintView.setBackgroundColor(DEFAULT_TINT_COLOR);
    mStatusBarTintView.setVisibility(View.GONE);
    decorViewGroup.addView(mStatusBarTintView);
}
 
Example 10
Project: qmui   File: QMUIDialog.java   View Source Code Vote up 5 votes
@Override
protected void onCreateContent(QMUIDialog dialog, ViewGroup parent) {
    if (mMessage != null && mMessage.length() != 0) {

        mTextView.setText(mMessage);
        mTextView.setPadding(
                QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal),
                QMUIResHelper.getAttrDimen(mContext, hasTitle() ? R.attr.qmui_dialog_content_padding_top : R.attr.qmui_dialog_content_padding_top_when_no_title),
                QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal),
                QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_content_padding_bottom)
        );
        parent.addView(mTextView);
    }
}
 
Example 11
Project: GitHub   File: StatusBarUtil.java   View Source Code Vote up 5 votes
/**
 * 设置状态栏颜色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity 需要设置的 activity
 * @param color    状态栏颜色值
 */
public static void setColorDiff(Activity activity, int color) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    // 生成一个状态栏大小的矩形
    View statusView = createStatusBarView(activity, color);
    // 添加 statusView 到布局中
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    decorView.addView(statusView);
    setRootView(activity);
}
 
Example 12
Project: NeteaseCloudMusic   File: DiscPagerAdapter.java   View Source Code Vote up 5 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = mInflater.inflate(R.layout.disc_pager_item, container,false);
    ImageView imageView = (ImageView) view.findViewById(R.id.iv_album);
    if (position>=0 && position<playlist.size()) {
        ImageCacheManager2.getInstance(container.getContext()).displayImage(imageView,playlist.get(position).getPath());
    }
    container.addView(view);
    return view;
}
 
Example 13
Project: ClouldReader   File: StatusBarUtils.java   View Source Code Vote up 5 votes
/**
 * 添加了一个状态栏(实际上是个view),放在了状态栏的垂直下方
 */
public static void addStatusBarBehind(Activity activity, @ColorInt int color, int statusBarAlpha) {
    //获取windowphone下的decorView
    ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    int       count     = decorView.getChildCount();
    //判断是否已经添加了statusBarView
    if (count > 0 && decorView.getChildAt(count - 1) instanceof StatusBarView) {
        decorView.getChildAt(count - 1).setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
    } else {
        //新建一个和状态栏高宽的view
        StatusBarView statusView = createStatusBarView(activity, color, statusBarAlpha);
        decorView.addView(statusView);
    }
    setRootView(activity);
}
 
Example 14
Project: sctalk   File: ViewPageAdapter.java   View Source Code Vote up 5 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {
    try {
        container.addView(mListViews.get(position), 0);// 添加页卡
        return mListViews.get(position);
    } catch (Exception e) {
        logger.e(e.getMessage());
        return null;
    }
}
 
Example 15
Project: UiLib   File: AutoLooperBanner.java   View Source Code Vote up 5 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {
    if (views.size() > 0) {
        //position % view.size()是指虚拟的position会在[0,view.size())之间循环
        View view = views.get(position % views.size());
        if (container.equals(view.getParent())) {
            container.removeView(view);
        }
        container.addView(view);
        return view;
    }
    return null;
}
 
Example 16
Project: airgram   File: IntroActivity.java   View Source Code Vote up 5 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {
    View view = View.inflate(container.getContext(), R.layout.intro_view_layout, null);
    TextView headerTextView = (TextView) view.findViewById(R.id.header_text);
    TextView messageTextView = (TextView) view.findViewById(R.id.message_text);
    container.addView(view, 0);

    headerTextView.setText(getString(titles[position]));
    messageTextView.setText(AndroidUtilities.replaceTags(getString(messages[position])));

    return view;
}
 
Example 17
Project: Phoenix-for-VK   File: AbsPagerAdapter.java   View Source Code Vote up 5 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {
    final H holder = createHolder(position, container);

    bindHolder(holder, position);

    mHolderSparseArray.put(position, holder);
    container.addView(holder.mItemView);
    return holder.mItemView;
}
 
Example 18
Project: Bailan   File: GalleryActivity.java   View Source Code Vote up 5 votes
@Override
public Object instantiateItem(ViewGroup paramViewGroup, int position) {
    ImageView imageView = new ImageView(this.context);
    this.viewList.add(imageView);
    paramViewGroup.addView(imageView);
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
    Glide.with(UIUtils.getContext()).load(urlList.get(position)).into(imageView);
    return imageView;
}
 
Example 19
Project: Trinity-App   File: ImagePagerAdapter.java   View Source Code Vote up 4 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {
    ImageView imageView = images.get(position);
    container.addView(imageView);
    return imageView;
}
 
Example 20
Project: Reer   File: AppearPageActivity.java   View Source Code Vote up 4 votes
@Override
public Object instantiateItem(ViewGroup container, int position) {  //这个方法用来实例化页卡
    container.addView(mListViews.get(position), 0);//添加页卡
    return mListViews.get(position);
}