android.view.ViewGroup#getContext ( )源码实例Demo

下面列出了android.view.ViewGroup#getContext ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public Object instantiateItem(ViewGroup container, int position) {
    Picture picture = mData.get(position);
    CenterCropImageView imageView = new CenterCropImageView(container.getContext());

    int w = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
    int h = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);

    imageView.measure(w, h);

    container.addView(imageView);
    ZjbImageLoader.create(picture.getUrl())
            .setDisplayType(ZjbImageLoader.DISPLAY_FADE_IN)
            .setQiniu(width, height)
            .setBitmapConfig(Bitmap.Config.RGB_565)
            .setFadeInTime(1000)
            .setDefaultDrawable(new ColorDrawable(0xffe0dedc))
            .into(imageView);
    imageView.setOnClickListener(v -> {
        if (null != mOnImageClickListener) {
            mOnImageClickListener.onClick(position);
        }
    });
    return imageView;
}
 
源代码2 项目: NIM_Android_UIKit   文件: BaseFetchLoadAdapter.java
@Override
public K onCreateViewHolder(ViewGroup parent, int viewType) {
    K baseViewHolder;
    this.mContext = parent.getContext();
    this.mLayoutInflater = LayoutInflater.from(mContext);
    switch (viewType) {
        case FETCHING_VIEW:
            baseViewHolder = getFetchingView(parent);
            break;
        case LOADING_VIEW:
            baseViewHolder = getLoadingView(parent);
            break;
        case EMPTY_VIEW:
            baseViewHolder = createBaseViewHolder(mEmptyView);
            break;
        default:
            baseViewHolder = onCreateDefViewHolder(parent, viewType);
    }
    return baseViewHolder;

}
 
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View homeView = inflater.inflate(R.layout.fragment_home, container, false);
    // Inflate the layout for this fragment
    // Extract tweets
    ArrayList<TweetModel> tweets = QueryUtils.extractTweets();


    // Setup Home Page Feed Adapter
    FeedAdapter adapter = new FeedAdapter(container.getContext(), tweets);

    //Setup RecyclerView from layout
    RecyclerView recyclerView = homeView.findViewById(R.id.recyclerview_feed);
    recyclerView.setHasFixedSize(true);
    //  Setting up linear layout for Recycler View
    LinearLayoutManager layoutManager = new LinearLayoutManager(container.getContext(), LinearLayoutManager.VERTICAL, false);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(layoutManager);

    return homeView;
}
 
源代码4 项目: aptoide-client-v8   文件: SearchResultAdapter.java
@Override public SearchResultItemView onCreateViewHolder(ViewGroup parent, int viewType) {
  final Context context = parent.getContext();
  View view = LayoutInflater.from(context)
      .inflate(viewType, parent, false);

  switch (viewType) {
    case SearchResultViewHolder.LAYOUT: {
      return new SearchResultViewHolder(view, onItemViewClick, query);
    }

    case SearchResultAdViewHolder.LAYOUT: {
      return new SearchResultAdViewHolder(view, onAdClickRelay, oneDecimalFormatter);
    }

    default: {
      return new SearchLoadingViewHolder(view);
    }
  }
}
 
源代码5 项目: FaceT   文件: ColorizeFaceActivity.java
@Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    Context context = parent.getContext();
    View view = getLayoutInflater().inflate(R.layout.makeup_product_row, parent, false);
    ProductViewHolder viewHolder = new ProductViewHolder(view);
    return viewHolder;
}
 
源代码6 项目: android-dev-challenge   文件: GreenAdapter.java
/**
 *
 * This gets called when each new ViewHolder is created. This happens when the RecyclerView
 * is laid out. Enough ViewHolders will be created to fill the screen and allow for scrolling.
 *
 * @param viewGroup The ViewGroup that these ViewHolders are contained within.
 * @param viewType  If your RecyclerView has more than one type of item (which ours doesn't) you
 *                  can use this viewType integer to provide a different layout. See
 *                  {@link android.support.v7.widget.RecyclerView.Adapter#getItemViewType(int)}
 *                  for more details.
 * @return A new NumberViewHolder that holds the View for each list item
 */
@Override
public NumberViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    Context context = viewGroup.getContext();
    int layoutIdForListItem = R.layout.number_list_item;
    LayoutInflater inflater = LayoutInflater.from(context);
    boolean shouldAttachToParentImmediately = false;

    View view = inflater.inflate(layoutIdForListItem, viewGroup, shouldAttachToParentImmediately);
    NumberViewHolder viewHolder = new NumberViewHolder(view);

    return viewHolder;
}
 
源代码7 项目: AndroidTvDemo   文件: ColorFocusBorder.java
@Override
public FocusBorder build(ViewGroup parent)
{
    if (null == parent)
    {
        throw new NullPointerException("The FocusBorder parent cannot be null");
    }
    final ColorFocusBorder boriderView =
        new ColorFocusBorder(parent.getContext(), mShimmerColor, mShimmerDuration, mIsShimmerAnim,
            mAnimDuration, mPaddingOfsetRectF, mShadowColor, mShadowWidth, mBorderColor, mBorderWidth);
    final ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(1, 1);
    parent.addView(boriderView, lp);
    return boriderView;
}
 
源代码8 项目: ProjectX   文件: ViewHolder.java
ViewHolder(ViewGroup parent) {
    super(new AppCompatTextView(parent.getContext()));
    mVText = (AppCompatTextView) itemView;
    mVText.setGravity(Gravity.CENTER);
    mVText.setBackgroundColor(0xff00dd00);
    mVText.setTextColor(0xffffffff);
}
 
源代码9 项目: delion   文件: AutofillEditorBase.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    setHasOptionsMenu(true);
    mContext = container.getContext();

    // We know which profile to edit based on the GUID stuffed in
    // our extras by AutofillPreferences.
    Bundle extras = getArguments();
    if (extras != null) {
        mGUID = extras.getString(AutofillPreferences.AUTOFILL_GUID);
    }
    if (mGUID == null) {
        mGUID = "";
        mIsNewEntry = true;
    } else {
        mIsNewEntry = false;
    }
    getActivity().setTitle(getTitleResourceId(mIsNewEntry));

    // Hide the top shadow on the ScrollView because the toolbar draws one.
    FadingEdgeScrollView scrollView = (FadingEdgeScrollView) inflater.inflate(
            R.layout.autofill_editor_base, container, false);
    scrollView.setShadowVisibility(false, true);

    // Inflate the editor and buttons into the "content" LinearLayout.
    LinearLayout contentLayout = (LinearLayout) scrollView.findViewById(R.id.content);
    inflater.inflate(getLayoutId(), contentLayout, true);
    inflater.inflate(R.layout.autofill_editor_base_buttons, contentLayout, true);

    return scrollView;
}
 
源代码10 项目: Dashchan   文件: DialogMenu.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	ListItem listItem = getItem(position);
	ViewHolder viewHolder;
	if (convertView == null) {
		viewHolder = new ViewHolder();
		View view = LayoutInflater.from(parent.getContext()).inflate(layoutResId, parent, false);
		if (listItem.checkable) {
			LinearLayout linearLayout = new LinearLayout(parent.getContext());
			linearLayout.setOrientation(LinearLayout.HORIZONTAL);
			linearLayout.setGravity(Gravity.CENTER_VERTICAL);
			linearLayout.addView(view, new LinearLayout.LayoutParams(0,
					LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
			CheckBox checkBox = new CheckBox(parent.getContext());
			checkBox.setClickable(false);
			checkBox.setFocusable(false);
			int paddingRight = view.getPaddingRight() - (int) (4f * ResourceUtils.obtainDensity(view));
			checkBox.setPadding(checkBox.getPaddingLeft(), checkBox.getPaddingTop(),
					Math.max(checkBox.getPaddingRight(), paddingRight), checkBox.getPaddingBottom());
			linearLayout.addView(checkBox, LinearLayout.LayoutParams.WRAP_CONTENT,
					LinearLayout.LayoutParams.WRAP_CONTENT);
			viewHolder.checkBox = checkBox;
			view = linearLayout;
		}
		viewHolder.textView = view.findViewById(android.R.id.text1);
		view.setTag(viewHolder);
		convertView = view;
	} else {
		viewHolder = (ViewHolder) convertView.getTag();
	}
	viewHolder.textView.setText(listItem.title);
	if (listItem.checkable) {
		viewHolder.checkBox.setChecked(listItem.checked);
	}
	return convertView;
}
 
源代码11 项目: PLDroidShortVideo   文件: VideoDivideActivity.java
@Override
public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    Context context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);

    View contactView = inflater.inflate(R.layout.item_devide_frame, parent, false);
    ItemViewHolder viewHolder = new ItemViewHolder(contactView);
    return viewHolder;
}
 
源代码12 项目: HomeApplianceMall   文件: ClassifyFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_classify, container, false);
    canAC = true;
    myApplication = (MyApplication)getActivity().getApplication();
    listView = (ListView) v.findViewById(R.id.listView_fclass);
    refreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.refreshLayout_f_class);
    layoutTv = (LinearLayout) v.findViewById(R.id.linearLayout_f_class_tv);
    layoutFridge = (LinearLayout) v.findViewById(R.id.linearLayout_f_class_fridge);
    layoutAir = (LinearLayout) v.findViewById(R.id.linearLayout_f_class_air);
    layoutGeyser = (LinearLayout) v.findViewById(R.id.linearLayout_f_class_geyser);
    layoutWasher = (LinearLayout) v.findViewById(R.id.linearLayout_f_class_washer);
    kindMap = new HashMap<>();
    listList = new ArrayList<>();

    refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            // 刷新操作
            int kind = myApplication.getCurrentKind();
            if(kind<0){
                kind = -1*kind;
                updateData(kind+"");
            }
        }
    });

    layoutTv.setOnClickListener(this);
    layoutFridge.setOnClickListener(this);
    layoutAir.setOnClickListener(this);
    layoutGeyser.setOnClickListener(this);
    layoutWasher.setOnClickListener(this);
    myAdape = new MyAdapterForListGoods(container.getContext(),listList);
    listView.setAdapter(myAdape);
    return v;
}
 
public RecyclerView.ViewHolder createLoadingViewHolder(ViewGroup parent) {
    FrameLayout frameLayout = new FrameLayout(parent.getContext());
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    frameLayout.setLayoutParams(lp);

    ProgressBar progressBar = new ProgressBar(parent.getContext());
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.CENTER;
    progressBar.setLayoutParams(layoutParams);
    frameLayout.addView(progressBar);

    return new StatusViewHolder(frameLayout);
}
 
源代码14 项目: expandable-recyclerview   文件: HDividerAdapter.java
@Override
public GroupVH onCreateGroupViewHolder(ViewGroup parent, int viewType) {
    Log.d(TAG, ">>> onCreateGroupViewHolder: " + viewType);
    Context context = parent.getContext();
    if (viewType == Shop.TYPE_ALL) {
        return new AllVH(LayoutInflater.from(context).inflate(R.layout.v_item_group_all, parent, false));
    } else if (viewType == Shop.TYPE_OFFLINE) {
        return new OffLineVH(LayoutInflater.from(context).inflate(R.layout.v_item_group_offline, parent, false));
    } else {
        return new OnLineVH(LayoutInflater.from(context).inflate(R.layout.v_item_group_online, parent, false));
    }
}
 
源代码15 项目: UniversalAdapter   文件: VanillaAdapter.java
@Override
protected VanillaHolder onCreateViewHolder(ViewGroup parent, int itemType) {
    return new VanillaHolder(new View(parent.getContext()));
}
 
源代码16 项目: KA27   文件: SeekBarCardView.java
@Override
public View getView(ViewGroup viewGroup) {
    return new SeekBarCardView(viewGroup.getContext(), list);
}
 
源代码17 项目: rv-adapter-states   文件: SimpleStringAdapter.java
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    return new ItemViewHolder(new TextView(parent.getContext()));
}
 
public View getView(int position, View convertView, ViewGroup parent) {
	FollowListItem item = null;
	if (convertView == null) {
		LinearLayout llItem = new LinearLayout(parent.getContext());
		item = new FollowListItem();
		llItem.setTag(item);
		convertView = llItem;

		item.aivIcon = new AsyncImageView(getContext());
		int dp_52 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 52);
		int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(parent.getContext(), 10);
		int dp_5 = cn.sharesdk.framework.utils.R.dipToPx(parent.getContext(), 5);
		LinearLayout.LayoutParams lpIcon = new LinearLayout.LayoutParams(dp_52, dp_52);
		lpIcon.gravity = Gravity.CENTER_VERTICAL;
		lpIcon.setMargins(dp_10, dp_5, dp_10, dp_5);
		item.aivIcon.setLayoutParams(lpIcon);
		llItem.addView(item.aivIcon);

		LinearLayout llText = new LinearLayout(parent.getContext());
		llText.setPadding(0, dp_10, dp_10, dp_10);
		llText.setOrientation(LinearLayout.VERTICAL);
		LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		lpText.gravity = Gravity.CENTER_VERTICAL;
		lpText.weight = 1;
		llText.setLayoutParams(lpText);
		llItem.addView(llText);

		item.tvName = new TextView(parent.getContext());
		item.tvName.setTextColor(0xff000000);
		item.tvName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
		item.tvName.setSingleLine();
		llText.addView(item.tvName);

		item.tvSign = new TextView(parent.getContext());
		item.tvSign.setTextColor(0x7f000000);
		item.tvSign.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
		item.tvSign.setSingleLine();
		llText.addView(item.tvSign);

		item.ivCheck = new ImageView(parent.getContext());
		item.ivCheck.setPadding(0, 0, dp_10, 0);
		LinearLayout.LayoutParams lpCheck = new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		lpCheck.gravity = Gravity.CENTER_VERTICAL;
		item.ivCheck.setLayoutParams(lpCheck);
		llItem.addView(item.ivCheck);
	} else {
		item = (FollowListItem) convertView.getTag();
	}

	Following following = getItem(position);
	item.tvName.setText(following.screeName);
	item.tvSign.setText(following.description);
	item.ivCheck.setImageBitmap(following.checked ? bmChd : bmUnch);
	if (isFling()) {
		Bitmap bm = BitmapProcessor.getBitmapFromCache(following.icon);
		if (bm != null && !bm.isRecycled()) {
			item.aivIcon.setImageBitmap(bm);
		} else {
			item.aivIcon.execute(null, AsyncImageView.DEFAULT_TRANSPARENT);
		}
	} else {
		item.aivIcon.execute(following.icon);
	}

	if (position == getCount() - 1) {
		next();
	}
	return convertView;
}
 
源代码19 项目: YCRefreshView   文件: NarrowImageAdapter.java
public NarrowImageViewHolder(ViewGroup parent) {
    super(new ImageView(parent.getContext()));
    imgPicture = (ImageView) itemView;
    imgPicture.setLayoutParams(new ViewGroup.LayoutParams((int) AppUtils.convertDpToPixel(72f,getContext()), ViewGroup.LayoutParams.MATCH_PARENT));
    imgPicture.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
 
源代码20 项目: CapturePacket   文件: CaptureListAdapter.java
@NonNull
@Override
public CaptureEntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    return new CaptureEntryViewHolder(parent.getContext(),mEntryTabDelegate);
}
 
 方法所在类