下面列出了android.widget.FrameLayout#setLayoutParams ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void initAfterRFABHelperBuild() {
realContentView = getContentView();
FrameLayout view = new FrameLayout(getContext());
view.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
realContentView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
view.addView(realContentView);
mAnimationView = new AnimationView(getContext());
ViewCompat.setLayerType(mAnimationView, ViewCompat.LAYER_TYPE_SOFTWARE, null);
mAnimationView.setLayoutParams(realContentView.getLayoutParams());
mAnimationView.setDrawView(realContentView);
mAnimationView.setOnViewAnimationDrawableListener(this);
view.addView(mAnimationView);
setRootView(view);
this.setMeasureAllChildren(true);
// this.measure(this.getMeasuredWidth(), this.getMeasuredHeight());
this.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
mAnimationView.setLayoutParams(new FrameLayout.LayoutParams(this.getMeasuredWidth(), this.getMeasuredHeight()));
mAnimationView.setMinRadius(onRapidFloatingActionListener.obtainRFAButton().getRfabProperties().getRealSizePx(getContext()) / 2);
mAnimationView.initialDraw();
}
private View createListView(ListView listView) {
ViewGroup contentContainer = (ViewGroup) mInflater.inflate(R.layout.fab__listview_container, null);
contentContainer.addView(mContentView);
mHeaderContainer = (FrameLayout) contentContainer.findViewById(R.id.fab__header_container);
initializeGradient(mHeaderContainer);
mHeaderContainer.addView(mHeaderView, 0);
mMarginView = new FrameLayout(listView.getContext());
mMarginView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, 0));
listView.addHeaderView(mMarginView, null, false);
// Make the background as high as the screen so that it fills regardless of the amount of scroll.
mListViewBackgroundView = contentContainer.findViewById(R.id.fab__listview_background);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mListViewBackgroundView.getLayoutParams();
params.height = Utils.getDisplayHeight(listView.getContext());
mListViewBackgroundView.setLayoutParams(params);
listView.setOnScrollListener(mOnScrollListener);
return contentContainer;
}
@Override
protected void apply(View view, TypedArray typedArray) {
boolean isBlur = typedArray.getBoolean(R.styleable.BlurDecorator_decorBlur, false);
if(!isBlur || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) return;
//i'm guessing this part here doesn't work because i'm using the same blur as ngAndroid and they are
//doing their injection in a different point in the inflation
ViewGroup parent = (ViewGroup) view.getParent();
FrameLayout layout = new FrameLayout(view.getContext());
layout.setLayoutParams(view.getLayoutParams());
int index = parent.indexOfChild(view);
parent.removeViewAt(index);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
view.setLayoutParams(layoutParams);
layout.addView(view);
parent.addView(layout, index);
final ImageView imageView = new ImageView(view.getContext());
imageView.setLayoutParams(layoutParams);
imageView.setVisibility(View.GONE);
layout.addView(imageView);
view.setVisibility(View.GONE);
view.setDrawingCacheEnabled(true);
imageView.setImageBitmap(BlurUtils.blurBitmap(view.getDrawingCache(), view.getContext()));
imageView.setVisibility(View.VISIBLE);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup fcontainer, @Nullable Bundle savedInstanceState) {
if (savedInstanceState == null) {
getChildFragmentManager().beginTransaction()
.add(new MediaPickerFragment(), "picker")
.commitNow();
}
root = new FrameLayout(getContext()) {
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (h != oldh && shareButtons != null) {
shareButtons.getLayoutParams().height = root.getHeight() - Screen.dp(135);
shareButtons.requestLayout();
}
}
};
root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
root.setBackgroundColor(getActivity().getResources().getColor(R.color.dialog_overlay));
root.setVisibility(View.INVISIBLE);
isLoaded = false;
// messenger().getGalleryScannerActor().send(new GalleryScannerActor.Show());
// messenger().getGalleryScannerActor().send(new GalleryScannerActor.Hide());
return root;
}
/**
* Attach the BadgeView to the target view
* @param target the view to attach the BadgeView
*/
public void setTargetView(View target) {
if (getParent() != null) {
((ViewGroup) getParent()).removeView(this);
}
if (target == null) {
return;
}
if (target.getParent() instanceof FrameLayout) {
((FrameLayout) target.getParent()).addView(this);
} else if (target.getParent() instanceof ViewGroup) {
// use a new Framelayout container for adding badge
ViewGroup parentContainer = (ViewGroup) target.getParent();
int groupIndex = parentContainer.indexOfChild(target);
parentContainer.removeView(target);
FrameLayout badgeContainer = new FrameLayout(getContext());
ViewGroup.LayoutParams parentLayoutParams = target.getLayoutParams();
badgeContainer.setLayoutParams(parentLayoutParams);
target.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
parentContainer.addView(badgeContainer, groupIndex, parentLayoutParams);
badgeContainer.addView(target);
badgeContainer.addView(this);
}
}
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);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
Resources res = getResources();
boolean isPortrait = res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
if (isPortrait) {
mColumnWidth = (int) (res.getDisplayMetrics().widthPixels * 0.87);
} else {
mColumnWidth = (int) (res.getDisplayMetrics().density * 320);
}
mGestureDetector = new GestureDetector(getContext(), new GestureListener());
mScroller = new Scroller(getContext(), new DecelerateInterpolator(1.1f));
mAutoScroller = new AutoScroller(getContext(), this);
mAutoScroller.setAutoScrollMode(snapToColumnWhenDragging() ? AutoScroller.AutoScrollMode.COLUMN : AutoScroller.AutoScrollMode
.POSITION);
mDragItem = new DragItem(getContext());
mRootLayout = new FrameLayout(getContext());
mRootLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
mColumnLayout = new LinearLayout(getContext());
mColumnLayout.setOrientation(LinearLayout.HORIZONTAL);
mColumnLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
mColumnLayout.setMotionEventSplittingEnabled(false);
mRootLayout.addView(mColumnLayout);
mRootLayout.addView(mDragItem.getDragItemView());
addView(mRootLayout);
}
@Override
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull FrameLayout child, @NonNull View dependency) {
int y = (int)dependency.getY();
int parentBottom = parent.getBottom();
int padding = parentBottom - y;
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) child.getLayoutParams();
params.setMargins(0, 0, 0, padding);
child.setLayoutParams(params);
return true;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
courseData = (EnrolledCoursesResponse) getArguments().getSerializable(Router.EXTRA_COURSE_DATA);
if (courseData != null) {
// The case where we have valid course data
getActivity().setTitle(courseData.getCourse().getName());
setHasOptionsMenu(courseData.getCourse().getCoursewareAccess().hasAccess());
environment.getAnalyticsRegistry().trackScreenView(
Analytics.Screens.COURSE_DASHBOARD, courseData.getCourse().getId(), null);
if (!courseData.getCourse().getCoursewareAccess().hasAccess()) {
final boolean auditAccessExpired = courseData.getAuditAccessExpires() != null &&
new Date().after(DateUtil.convertToDate(courseData.getAuditAccessExpires()));
errorLayoutBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_dashboard_error_layout, container, false);
errorLayoutBinding.errorMsg.setText(auditAccessExpired ? R.string.course_access_expired : R.string.course_not_started);
return errorLayoutBinding.getRoot();
} else {
return super.onCreateView(inflater, container, savedInstanceState);
}
} else if (getArguments().getBoolean(ARG_COURSE_NOT_FOUND)) {
// The case where we have invalid course data
errorLayoutBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_dashboard_error_layout, container, false);
errorLayoutBinding.errorMsg.setText(R.string.cannot_show_dashboard);
return errorLayoutBinding.getRoot();
} else {
// The case where we need to fetch course's data based on its courseId
fetchCourseById();
final FrameLayout frameLayout = new FrameLayout(getActivity());
frameLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
frameLayout.addView(inflater.inflate(R.layout.loading_indicator, container, false));
return frameLayout;
}
}
public View setError(final int res) {
FrameLayout container = new FrameLayout(getContext());
container.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
LayoutInflater.from(getContext()).inflate(res, container);
getEventDelegate().setErrorMore(container);
return container;
}
static View getLocationItem() {
LinearLayout mainContainer = new LinearLayout(G.context);
mainContainer.setId(R.id.mainContainer);
LinearLayout.LayoutParams layout_761 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mainContainer.setLayoutParams(layout_761);
LinearLayout linearLayout_532 = new LinearLayout(G.context);
linearLayout_532.setOrientation(VERTICAL);
LinearLayout.LayoutParams layout_639 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
linearLayout_532.setLayoutParams(layout_639);
LinearLayout contentContainer = new LinearLayout(G.context);
contentContainer.setId(R.id.contentContainer);
LinearLayout.LayoutParams layoutParamsContentContainer = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
contentContainer.setPadding(i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4));
contentContainer.setLayoutParams(layoutParamsContentContainer);
LinearLayout m_container = new LinearLayout(G.context);
m_container.setId(R.id.m_container);
m_container.setOrientation(VERTICAL);
LinearLayout.LayoutParams layout_788 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
m_container.setLayoutParams(layout_788);
FrameLayout frameLayout = new FrameLayout(G.context);
frameLayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));
ReserveSpaceRoundedImageView reserveSpaceRoundedImageView = new ReserveSpaceRoundedImageView(G.context);
reserveSpaceRoundedImageView.setId(R.id.thumbnail);
reserveSpaceRoundedImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
reserveSpaceRoundedImageView.setCornerRadius((int) G.context.getResources().getDimension(R.dimen.messageBox_cornerRadius));
LinearLayout.LayoutParams layout_758 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
reserveSpaceRoundedImageView.setLayoutParams(layout_758);
mainContainer.addView(linearLayout_532);
linearLayout_532.addView(contentContainer);
contentContainer.addView(m_container);
m_container.addView(frameLayout);
frameLayout.addView(reserveSpaceRoundedImageView);
return mainContainer;
}
public EventFooter(){
container = new FrameLayout(adapter.getContext());
container.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
private FrameLayout getBar(final String title, final int value, final int index) {
int maxValue = (int) (mMaxValue * 100);
LinearLayout linearLayout = new LinearLayout(mContext);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT
);
params.gravity = Gravity.CENTER;
linearLayout.setLayoutParams(params);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setGravity(Gravity.CENTER);
//Adding bar
Bar bar = new Bar(mContext, null, android.R.attr.progressBarStyleHorizontal);
bar.setProgress(value);
bar.setVisibility(View.VISIBLE);
bar.setIndeterminate(false);
bar.setMax(maxValue);
bar.setProgressDrawable(ContextCompat.getDrawable(mContext, R.drawable.progress_bar_shape));
LayoutParams progressParams = new LayoutParams(
mBarWidth,
mBarHeight
);
progressParams.gravity = Gravity.CENTER;
bar.setLayoutParams(progressParams);
BarAnimation anim = new BarAnimation(bar, 0, value);
anim.setDuration(250);
bar.startAnimation(anim);
LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable();
layerDrawable.mutate();
GradientDrawable emptyLayer = (GradientDrawable) layerDrawable.getDrawable(0);
ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1);
emptyLayer.setColor(ContextCompat.getColor(mContext, mEmptyColor));
emptyLayer.setCornerRadius(mBarRadius);
GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable();
if (progressLayer != null) {
progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor));
progressLayer.setCornerRadius(mBarRadius);
}
linearLayout.addView(bar);
//Adding txt below bar
TextView txtBar = new TextView(mContext);
LayoutParams txtParams = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
txtBar.setTextSize(getSP(mBarTitleTxtSize));
txtBar.setText(title);
txtBar.setGravity(Gravity.CENTER);
txtBar.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor));
txtBar.setPadding(0, mBarTitleMarginTop, 0, 0);
txtBar.setLayoutParams(txtParams);
linearLayout.addView(txtBar);
FrameLayout rootFrameLayout = new FrameLayout(mContext);
LinearLayout.LayoutParams rootParams = new LinearLayout.LayoutParams(
0,
LayoutParams.MATCH_PARENT,
1f
);
rootParams.gravity = Gravity.CENTER;
//rootParams.setMargins(0, h, 0, h);
rootFrameLayout.setLayoutParams(rootParams);
//Adding bar + title
rootFrameLayout.addView(linearLayout);
if (isBarCanBeClick)
rootFrameLayout.setOnClickListener(barClickListener);
rootFrameLayout.setTag(index);
return rootFrameLayout;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
try {
openAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_in);
closeAnimation = AnimationUtils.loadAnimation(this, R.anim.scale_out);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
setTheme(R.style.Theme_TMessages);
getWindow().setBackgroundDrawableResource(R.drawable.transparent);
contentView = new FrameLayoutTouch(this);
setContentView(contentView, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
containerViewBack = new FrameLayout(this);
contentView.addView(containerViewBack);
containerView = new FrameLayout(this);
contentView.addView(containerView);
shadowView = new FrameLayout(this);
contentView.addView(shadowView);
shadowView.setBackgroundResource(R.drawable.shadow);
ViewGroup.LayoutParams layoutParams = shadowView.getLayoutParams();
layoutParams.width = OSUtilities.dp(2);
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
shadowView.setLayoutParams(layoutParams);
shadowView.setVisibility(View.INVISIBLE);
actionBar = new ActionBar(this);
contentView.addView(actionBar);
layoutParams = actionBar.getLayoutParams();
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
actionBar.setLayoutParams(layoutParams);
for (BaseFragment fragment : fragmentsStack) {
fragment.setParentActivity(this);
}
needLayout();
}
public void onCreate() {
LinearLayout llPage = new LinearLayout(getContext());
llPage.setBackgroundColor(0xfff5f5f5);
llPage.setOrientation(LinearLayout.VERTICAL);
activity.setContentView(llPage);
// 标题栏
llTitle = new TitleLayout(getContext());
int resId = getBitmapRes(getContext(), "title_back");
if (resId > 0) {
llTitle.setBackgroundResource(resId);
}
llTitle.getBtnBack().setOnClickListener(this);
resId = getStringRes(getContext(), "multi_share");
if (resId > 0) {
llTitle.getTvTitle().setText(resId);
}
llTitle.getBtnRight().setVisibility(View.VISIBLE);
resId = getStringRes(getContext(), "finish");
if (resId > 0) {
llTitle.getBtnRight().setText(resId);
}
llTitle.getBtnRight().setOnClickListener(this);
llTitle.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
llPage.addView(llTitle);
FrameLayout flPage = new FrameLayout(getContext());
LinearLayout.LayoutParams lpFl = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lpFl.weight = 1;
flPage.setLayoutParams(lpFl);
llPage.addView(flPage);
// 关注(或朋友)列表
PullToRefreshView followList = new PullToRefreshView(getContext());
FrameLayout.LayoutParams lpLv = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
followList.setLayoutParams(lpLv);
flPage.addView(followList);
adapter = new FollowAdapter(followList);
adapter.setPlatform(platform);
followList.setAdapter(adapter);
adapter.getListView().setOnItemClickListener(this);
ImageView ivShadow = new ImageView(getContext());
resId = getBitmapRes(getContext(), "title_shadow");
if (resId > 0) {
ivShadow.setBackgroundResource(resId);
}
FrameLayout.LayoutParams lpSd = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
ivShadow.setLayoutParams(lpSd);
flPage.addView(ivShadow);
// 请求数据
followList.performPulling(true);
}
public void onCreate() {
activity.getWindow().setBackgroundDrawable(new ColorDrawable(0xfff3f3f3));
llPage = new LinearLayout(activity);
llPage.setOrientation(LinearLayout.VERTICAL);
activity.setContentView(llPage);
rlTitle = new RelativeLayout(activity);
float ratio = getRatio();
int titleHeight = (int) (getDesignTitleHeight() * ratio);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, titleHeight);
llPage.addView(rlTitle, lp);
initTitle(rlTitle, ratio);
View line = new View(activity);
LinearLayout.LayoutParams lpline = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, (int) (ratio < 1 ? 1 : ratio));
line.setBackgroundColor(0xffdad9d9);
llPage.addView(line, lpline);
FrameLayout flPage = new FrameLayout(getContext());
LinearLayout.LayoutParams lpFl = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lpFl.weight = 1;
flPage.setLayoutParams(lpFl);
llPage.addView(flPage);
// 关注(或朋友)列表
PullToRequestView followList = new PullToRequestView(getContext());
FrameLayout.LayoutParams lpLv = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
followList.setLayoutParams(lpLv);
flPage.addView(followList);
adapter = new FriendAdapter(this, followList);
adapter.setPlatform(platform);
adapter.setRatio(ratio);
adapter.setOnItemClickListener(this);
followList.setAdapter(adapter);
// 请求数据
followList.performPullingDown(true);
}
public void onCreate() {
activity.getWindow().setBackgroundDrawable(new ColorDrawable(0xfff3f3f3));
llPage = new LinearLayout(activity);
llPage.setOrientation(LinearLayout.VERTICAL);
activity.setContentView(llPage);
rlTitle = new RelativeLayout(activity);
float ratio = getRatio();
int titleHeight = (int) (getDesignTitleHeight() * ratio);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, titleHeight);
llPage.addView(rlTitle, lp);
initTitle(rlTitle, ratio);
View line = new View(activity);
LinearLayout.LayoutParams lpline = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, (int) (ratio < 1 ? 1 : ratio));
line.setBackgroundColor(0xffdad9d9);
llPage.addView(line, lpline);
FrameLayout flPage = new FrameLayout(getContext());
LinearLayout.LayoutParams lpFl = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lpFl.weight = 1;
flPage.setLayoutParams(lpFl);
llPage.addView(flPage);
// 关注(或朋友)列表
PullToRequestView followList = new PullToRequestView(getContext());
FrameLayout.LayoutParams lpLv = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
followList.setLayoutParams(lpLv);
flPage.addView(followList);
adapter = new FriendAdapter(this, followList);
adapter.setPlatform(platform);
adapter.setRatio(ratio);
adapter.setOnItemClickListener(this);
followList.setAdapter(adapter);
// 请求数据
followList.performPullingDown(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
BindedDisplayList<Dialog> displayList = messenger().getDialogsDisplayList();
if (displayList.getListProcessor() == null) {
displayList.setListProcessor((items, previous) -> {
for (Dialog d : items) {
if (d.getSenderId() != 0) {
users().get(d.getSenderId());
}
}
return null;
});
}
View res = inflate(inflater, container, R.layout.fragment_dialogs, displayList);
res.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
// Footer
FrameLayout footer = new FrameLayout(getActivity());
footer.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(160)));
footer.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
addFooterView(footer);
// Header
View header = new View(getActivity());
header.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(ActorSDK.sharedActor().style.getDialogsPaddingTopDp())));
header.setBackgroundColor(ActorSDK.sharedActor().style.getMainBackgroundColor());
addHeaderView(header);
// Empty View
emptyDialogs = res.findViewById(R.id.emptyDialogs);
bind(messenger().getAppState().getIsDialogsEmpty(), (val, Value) -> {
if (val) {
emptyDialogs.setVisibility(View.VISIBLE);
} else {
emptyDialogs.setVisibility(View.GONE);
}
});
((TextView) res.findViewById(R.id.add_contact_hint_text)).setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
((TextView) emptyDialogs.findViewById(R.id.empty_dialogs_text)).setTextColor(ActorSDK.sharedActor().style.getMainColor());
emptyDialogs.findViewById(R.id.empty_dialogs_bg).setBackgroundColor(ActorSDK.sharedActor().style.getMainColor());
return res;
}
private boolean addNewLayout(View targetView) {
// check current views
if (getParent() != null || targetView == null || targetView.getParent() == null || viewContainerId != -1) {
return false;
}
ViewGroup parentContainer = (ViewGroup) targetView.getParent();
// if the current view is framelayout
if (targetView.getParent() instanceof FrameLayout) {
((FrameLayout) targetView.getParent()).addView(this);
} else if (targetView.getParent() instanceof ViewGroup) {
// get the index of the tagretview
int targetViewIndex = parentContainer.indexOfChild(targetView);
// generate new ID
viewContainerId = generateViewId();
// if relative layout
if (targetView.getParent() instanceof RelativeLayout) {
// loop through the tagetView parent childs
for (int i = 0; i < parentContainer.getChildCount(); i++) {
if (i == targetViewIndex) {
continue;
}
View view = parentContainer.getChildAt(i);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
for (int j = 0; j < layoutParams.getRules().length; j++) {
if (layoutParams.getRules()[j] == targetView.getId()) {
layoutParams.getRules()[j] = viewContainerId;
}
}
view.setLayoutParams(layoutParams);
}
}
parentContainer.removeView(targetView);
// new layout
FrameLayout lightTextViewContainer = new FrameLayout(getContext());
ViewGroup.LayoutParams targetLayoutParam = targetView.getLayoutParams();
lightTextViewContainer.setLayoutParams(targetLayoutParam);
targetView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// add target and label in this layout
lightTextViewContainer.addView(targetView);
lightTextViewContainer.addView(this);
lightTextViewContainer.setId(viewContainerId);
// add layout in parent container
parentContainer.addView(lightTextViewContainer, targetViewIndex, targetLayoutParam);
}
return true;
}
private boolean replaceLayout(View target) {
if (getParent() != null || target == null || target.getParent() == null || _labelViewContainerID != -1) {
return false;
}
ViewGroup parentContainer = (ViewGroup) target.getParent();
if (target.getParent() instanceof FrameLayout) {
((FrameLayout) target.getParent()).addView(this);
} else if (target.getParent() instanceof ViewGroup) {
int groupIndex = parentContainer.indexOfChild(target);
_labelViewContainerID = generateViewId();
// relativeLayout need copy rule
if (target.getParent() instanceof RelativeLayout) {
for (int i = 0; i < parentContainer.getChildCount(); i++) {
if (i == groupIndex) {
continue;
}
View view = parentContainer.getChildAt(i);
RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams();
for (int j = 0; j < para.getRules().length; j++) {
if (para.getRules()[j] == target.getId()) {
para.getRules()[j] = _labelViewContainerID;
}
}
view.setLayoutParams(para);
}
}
parentContainer.removeView(target);
// new dummy layout
FrameLayout labelViewContainer = new FrameLayout(getContext());
ViewGroup.LayoutParams targetLayoutParam = target.getLayoutParams();
labelViewContainer.setLayoutParams(targetLayoutParam);
target.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// add target and label in dummy layout
labelViewContainer.addView(target);
labelViewContainer.addView(this);
labelViewContainer.setId(_labelViewContainerID);
// add dummy layout in parent container
parentContainer.addView(labelViewContainer, groupIndex, targetLayoutParam);
}
return true;
}