下面列出了怎么用android.support.annotation.LayoutRes的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Create a new popup window
*
* @param context Context
* @param resource The popup's layout resource
* @param width The popup's width
* @param height The popup's height
* @param focusable True if the popup can be focused, false otherwise
* @param animationStyle Animation style to use when the popup appears
* and disappears. Set to -1 for the default animation, 0 for no
* animation, or a resource identifier for an explicit animation.
*/
public AbstractPopup(Context context, @LayoutRes int resource, int width, int height, boolean focusable, int animationStyle) {
/*
* LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
*/
super(LayoutInflater.from(context).inflate(resource, null), width, height, focusable);
this.mContext = context;
this.mRootView = getContentView();
if (animationStyle != -1) {
setAnimationStyle(animationStyle);
}
setOutsideTouchable(true);
setFocusable(true);
setClippingEnabled(true);
setBackgroundDrawable(new BitmapDrawable());
init();
}
/**
* 添加加载更多footer layout
*
* @param loadMoreFooterLayoutRes
*/
public void setLoadMoreFooterView(@LayoutRes int loadMoreFooterLayoutRes) {
ensureLoadMoreFooterContainer();
final View loadMoreFooter = LayoutInflater.from(getContext()).inflate(loadMoreFooterLayoutRes, mLoadMoreFooterContainer, false);
if (loadMoreFooter != null) {
setLoadMoreFooterView(loadMoreFooter);
}
}
public BaseAdapter(Collection<T> data, @LayoutRes int layout, OnItemClickListener<V> listener) {
this.data = new ArrayList<>();
if (data != null) {
this.data.addAll(data);
}
this.layouts = layout;
this.listener = listener;
spLayout = new SparseIntArray();
spLayout.put(TYPE_NOMAL, this.layouts);
headerList.addChangeListener(this);
}
private void init(@LayoutRes int layoutId) {
LayoutInflater.from(getContext()).inflate(layoutId, this, true);
findViewById(R.id.new_account_action).setOnClickListener(this);
findViewById(R.id.import_account_action).setOnClickListener(this);
ViewPager viewPager = (ViewPager)findViewById(R.id.intro);
if (viewPager != null) {
viewPager.setPageTransformer(false, new DepthPageTransformer());
viewPager.setAdapter(new IntroPagerAdapter());
}
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (null == inflater) {
return;
}
setContentView(inflater.inflate(layoutResID, null));
}
public HiddenAdapter(Context context, ContentFragment mainFrag, Futils utils, @LayoutRes int layoutId,
ArrayList<HFile> items, MaterialDialog materialDialog, boolean hide) {
addAll(items);
this.utils = utils;
this.c = context;
this.context = mainFrag;
this.items = items;
this.hide = hide;
this.materialDialog = materialDialog;
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
super.setContentView(layoutResID);
super.setContentView(R.layout.w_layout_act_root);
setRootView();
LayoutInflater.from(this).inflate(layoutResID, mFlContainer,true);
}
public View setTitleLayout(@LayoutRes int layoutResId) {
TypedValue tv = new TypedValue();
int actionBarHeight = mContext.getResources().getDimensionPixelSize(R.dimen.mei_48_dp);
if (mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, mContext
.getResources().getDisplayMetrics());
}
return setTitleLayout(layoutResId, actionBarHeight);
}
/**
* set empty layout
*
* @param layoutResId
* @return
*/
public View setEmptyLayout(@LayoutRes int layoutResId) {
if (mEmptyView != null) return mEmptyView;
setViewStubLayoutRes(R.id.base_empty_stub, layoutResId);
mEmptyView = inflateViewStub(R.id.base_empty_stub);
return mEmptyView;
}
/**
* set loading layout
*
* @param layoutResId
* @return
*/
public View setLoadingLayout(@LayoutRes int layoutResId) {
if (mLoadingView != null) return mLoadingView;
setViewStubLayoutRes(R.id.base_loading_stub, layoutResId);
mLoadingView = inflateViewStub(R.id.base_loading_stub);
return mLoadingView;
}
/**
* set error layout
*
* @param layoutResId
* @return
*/
public View setErrorLayout(@LayoutRes int layoutResId) {
if (mErrorView != null) return mErrorView;
setViewStubLayoutRes(R.id.base_error_stub, layoutResId);
mErrorView = inflateViewStub(R.id.base_error_stub);
return mErrorView;
}
/**
* 添加刷新header layout
*
* @param refreshHeaderLayoutRes
*/
public void setRefreshHeaderView(@LayoutRes int refreshHeaderLayoutRes) {
ensureRefreshHeaderContainer();
final View refreshHeader = LayoutInflater.from(getContext()).inflate(refreshHeaderLayoutRes, mRefreshHeaderContainer, false);
if (refreshHeader != null) {
setRefreshHeaderView(refreshHeader);
}
}
/**
* 返回布局id
*
* @return 返回布局id
* @throws @exception NullPointerException 当没有申明此注解是抛出此异常
* @see Layout
*/
private @LayoutRes
int getLayout() {
if (getClass().isAnnotationPresent(Layout.class)) {
return getClass().getAnnotation(Layout.class).value();
} else {
throw new NullPointerException("You must declare that layout is annotated on the class");
}
}
@SuppressWarnings("unchecked")
public CodeSuggestAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull ArrayList<Description> objects) {
super(context, resource, objects);
this.inflater = LayoutInflater.from(context);
this.context = context;
this.clone = (ArrayList<Description>) objects.clone();
this.suggestion = new ArrayList<>();
this.resourceID = resource;
AppSetting appSetting = new AppSetting(context);
editorTextSize = appSetting.getEditorTextSize();
}
public Builder(String key,
String title,
@LayoutRes int customDialogViewId)
{
//todo don't forget to pass your own id's here!
super(key,
title,
null,
R.id.textView_basicSettingsObject_title,
R.id.textView_basicSettingsObject_summary,
ESettingsTypes.VOID,
R.id.imageView_basicSettingsObject_icon);
this.customViewId = customDialogViewId;
}
private void init(@LayoutRes int layoutId) {
LayoutInflater.from(getContext()).inflate(layoutId, this, true);
findViewById(R.id.new_account_action).setOnClickListener(this);
findViewById(R.id.import_account_action).setOnClickListener(this);
ViewPager viewPager = findViewById(R.id.intro);
if (viewPager != null) {
viewPager.setPageTransformer(false, new DepthPageTransformer());
viewPager.setAdapter(new IntroPagerAdapter());
}
}
/**
* 根据布局文件 Id 得到对应的 View,并设置控件属性、绑定接口
*/
private View generateStatusView(@LayoutRes int layoutId) {
View statusView = viewArray.get(layoutId);
if (statusView == null) {
statusView = inflate(layoutId);
viewArray.put(layoutId, statusView);
configStatusView(layoutId, statusView);
}
return statusView;
}
private void init(@LayoutRes int layoutId, @NonNull Wallet wallet) {
this.wallet = wallet;
LayoutInflater.from(getContext()).inflate(layoutId, this, true);
findViewById(R.id.action_coinbase).setOnClickListener(this);
findViewById(R.id.action_shapeshift).setOnClickListener(this);
findViewById(R.id.action_changelly).setOnClickListener(this);
}
@LayoutRes
public abstract int getLayoutResId();
@LayoutRes
public abstract int getLayout();
public final void addHeaderView(@LayoutRes int layout) {
headerList.add(new DataBean(layout));
}
public void setHeaderLayoutId(@LayoutRes int headerLayoutId) {
this.headerLayoutId = headerLayoutId;
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}
protected void setDefaultViewTypeLayout(@LayoutRes int layoutResId) {
addItemType(DEFAULT_VIEW_TYPE, layoutResId);
}
@LayoutRes
int layoutResID();
public BaseRecyclerAdapter(@NonNull List<T> data, @LayoutRes int layoutResId) {
mData = data;
mLayoutResId = layoutResId;
mSelectedItems = new SparseArray<>();
}
public BaseItemAdapter(@LayoutRes int itemLayoutId) {
setItemLayoutId(itemLayoutId);
}
public @LayoutRes
int getItemLayoutId() {
return itemLayoutId;
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}