下面列出了android.widget.LinearLayout#removeView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode)
{
case HomeActivity.RC_ASSET_EXTERNAL_WRITE_PERM:
if (viewModel.createDirectory())
{
LinearLayout advancedSettingsLayout = findViewById(R.id.layout);
advancedSettingsLayout.removeView(tokenScript);
showAlphaWalletDirectoryConfirmation();
//need to set up the listener
viewModel.startFileListeners();
}
break;
}
}
private void setupContent(LinearLayout contentPanel) {
mScrollView = (ScrollView) mWindow.findViewById(R.id.scrollView);
mScrollView.setFocusable(false);
mTextMessage = (TextView) mWindow.findViewById(R.id.message);
if (mTextMessage == null) {
return;
} else if (!TextUtils.isEmpty(message)) {
mTextMessage.setText(message);
} else {
mTextMessage.setVisibility(View.GONE);
mScrollView.removeView(mTextMessage);
if (mListView != null) {
contentPanel.removeView(mScrollView);
contentPanel.addView(mListView, new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
contentPanel.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, 0, 1.0f));
} else {
contentPanel.setVisibility(View.GONE);
}
}
}
private View createSkeleton() {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout rootLayout = (LinearLayout) inflater.inflate(
R.layout.dialog_main_skeleton, new FrameLayout(mContext), false);
TextView titleView = (TextView) rootLayout.findViewById(R.id.title);
if (Device.hasLollipopApi()) {
// The dividers are quite ugly with material design.
rootLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
}
if (mTitleText == null && mIcon == null) {
rootLayout.removeView(titleView);
} else {
if (mTitleText != null)
titleView.setText(mTitleText);
if (mIcon != null)
titleView.setCompoundDrawablesWithIntrinsicBounds(mIcon, null, null, null);
}
return rootLayout;
}
private void setContent() {
if (!isShowBubble() && !isMiddleItem()) {
return;
}
LinearLayout bodyContainer = (LinearLayout) view.findViewById(R.id.message_item_body);
// 调整container的位置
int index = isReceivedMessage() ? 0 : 4;
if (bodyContainer.getChildAt(index) != contentContainer) {
bodyContainer.removeView(contentContainer);
bodyContainer.addView(contentContainer, index);
}
if (isMiddleItem()) {
setGravity(bodyContainer, Gravity.CENTER);
} else {
if (isReceivedMessage()) {
setGravity(bodyContainer, Gravity.LEFT);
contentContainer.setBackgroundResource(leftBackground());
} else {
setGravity(bodyContainer, Gravity.RIGHT);
contentContainer.setBackgroundResource(rightBackground());
}
}
}
private LinearLayout generateLayout(String text){
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dialog_item_button_layout, null);
View v_line = layout.findViewById(R.id.v_line);
TextView tv_text = (TextView) layout.findViewById(R.id.tv_text);
tv_text.setText(text);
if (ll_bottom_button.getChildCount() == 0){
layout.removeView(v_line);
tv_text.setBackgroundResource(R.drawable.dialog_button_bottom_selector);
}
else if (ll_bottom_button.getChildCount() == 1){
tv_text.setBackgroundResource(R.drawable.dialog_button_bottomright_selector);
}
else{
tv_text.setBackgroundResource(R.drawable.dialog_button_bottomright_selector);
}
reBuildCircle();
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.weight = 1;
layout.setLayoutParams(params);
layout.setOnClickListener(this);
return layout;
}
private void setupContent(LinearLayout contentPanel) {
this.mScrollView = (ScrollView)this.findViewById(R.id.scrollView);
this.mScrollView.setFocusable(false);
this.mMessageView = (TextView)this.findViewById(R.id.message);
if(this.mMessageView != null) {
if(this.mMessage != null) {
this.mMessageView.setText(this.mMessage);
} else {
this.mMessageView.setVisibility(8);
this.mScrollView.removeView(this.mMessageView);
if(this.mListView != null) {
contentPanel.removeView(this.findViewById(R.id.scrollView));
contentPanel.addView(this.mListView, new android.widget.LinearLayout.LayoutParams(-1, -1));
contentPanel.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, 0, 1.0F));
} else {
contentPanel.setVisibility(8);
}
}
}
}
private void initRecyclerView() {
mFeedArticleDataList = new ArrayList<>();
mAdapter = new ArticleListAdapter(R.layout.item_search_pager, mFeedArticleDataList);
mAdapter.setOnItemClickListener((adapter, view, position) -> startArticleDetailPager(view, position));
mAdapter.setOnItemChildClickListener((adapter, view, position) -> clickChildEvent(view, position));
mRecyclerView.setLayoutManager(new LinearLayoutManager(_mActivity));
mRecyclerView.setHasFixedSize(true);
//add head banner
LinearLayout mHeaderGroup = ((LinearLayout) LayoutInflater.from(_mActivity).inflate(R.layout.head_banner, null));
mBanner = mHeaderGroup.findViewById(R.id.head_banner);
mHeaderGroup.removeView(mBanner);
mAdapter.addHeaderView(mBanner);
mRecyclerView.setAdapter(mAdapter);
}
public void removeFromLayout(@NonNull LinearLayout parent)
{
if (layout != null)
{
parent.removeView(layout);
layout.setVisibility(View.GONE);
}
}
private void switchItemFromPosition(int change,View view){
LinearLayout parentLayout = (LinearLayout)(view.getParent());
int columnPos = parentLayout.indexOfChild(view);
if (columnPos + change >= 0 && columnPos + change < parentLayout.getChildCount()) {
parentLayout.removeView(view);
parentLayout.addView(view, columnPos + change);
if (mDragItemStartCallback != null) {
int newPos = parentLayout.indexOfChild(view);
last_swap = System.currentTimeMillis();
mLastSwap = newPos;
int newColumnPos = ((LinearLayout) mobileView.getParent().getParent().getParent().getParent()).indexOfChild((View) (mobileView.getParent().getParent().getParent()));
mDragItemStartCallback.changedPosition(view, originalItemPosition, originalPosition, newPos, newColumnPos);
}
}
}
/**
* Adds an icon with a descriptive message to the layout.
*
* -----------------------------------------------------
* | ICON | PRIMARY MESSAGE SECONDARY MESSAGE |
* -----------------------------------------------------
* If an icon is not provided, the ImageView that would normally show it is hidden.
*
* @param iconResourceId ID of the drawable to use for the icon.
* @param iconColorId ID of the tint color for the icon, or 0 for default.
* @param primaryMessage Message to display for the toggle.
* @param secondaryMessage Additional descriptive text for the toggle. May be null.
*/
public View addIcon(int iconResourceId, int iconColorId, CharSequence primaryMessage,
CharSequence secondaryMessage) {
LinearLayout layout = (LinearLayout) LayoutInflater.from(getContext()).inflate(
R.layout.infobar_control_icon_with_description, this, false);
addView(layout, new ControlLayoutParams());
ImageView iconView = (ImageView) layout.findViewById(R.id.control_icon);
iconView.setImageResource(iconResourceId);
if (iconColorId != 0) {
iconView.setColorFilter(ApiCompatibilityUtils.getColor(getResources(), iconColorId));
}
// The primary message text is always displayed.
TextView primaryView = (TextView) layout.findViewById(R.id.control_message);
primaryView.setText(primaryMessage);
// The secondary message text is optional.
TextView secondaryView =
(TextView) layout.findViewById(R.id.control_secondary_message);
if (secondaryMessage == null) {
layout.removeView(secondaryView);
} else {
secondaryView.setText(secondaryMessage);
}
return layout;
}
public void moveSectionToTop(int sectionLayoutID)
{
View sectionLayout = findViewById(sectionLayoutID);
LinearLayout settingsLayout = (LinearLayout)findViewById(R.id.appwidget_settings_layout);
if (sectionLayout != null && settingsLayout != null)
{
settingsLayout.removeView(sectionLayout);
settingsLayout.addView(sectionLayout, 0);
}
}
/**
* Creates a standard toggle switch and adds it to the layout.
*
* -------------------------------------------------
* | ICON | MESSAGE | TOGGLE |
* -------------------------------------------------
* If an icon is not provided, the ImageView that would normally show it is hidden.
*
* @param iconResourceId ID of the drawable to use for the icon, or 0 to hide the ImageView.
* @param iconColorId ID of the tint color for the icon, or 0 for default.
* @param toggleMessage Message to display for the toggle.
* @param toggleId ID to use for the toggle.
* @param isChecked Whether the toggle should start off checked.
*/
public View addSwitch(int iconResourceId, int iconColorId, CharSequence toggleMessage,
int toggleId, boolean isChecked) {
LinearLayout switchLayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(
R.layout.infobar_control_toggle, this, false);
addView(switchLayout, new ControlLayoutParams());
ImageView iconView = (ImageView) switchLayout.findViewById(R.id.control_icon);
if (iconResourceId == 0) {
switchLayout.removeView(iconView);
} else {
iconView.setImageResource(iconResourceId);
if (iconColorId != 0) {
iconView.setColorFilter(
ApiCompatibilityUtils.getColor(getResources(), iconColorId));
}
}
TextView messageView = (TextView) switchLayout.findViewById(R.id.control_message);
messageView.setText(toggleMessage);
SwitchCompat switchView =
(SwitchCompat) switchLayout.findViewById(R.id.control_toggle_switch);
switchView.setId(toggleId);
switchView.setChecked(isChecked);
return switchLayout;
}
/**
* 显示占位布局
*
* @param type {@link TempView#ERROR}
* {@link TempView#DATA_NULL}
* {@link TempView#LOADING}
*/
protected void showTempView(int type) {
if (mTempView == null || !useTempView) {
return;
}
mTempView.setType(type);
if (mParent != null) {
int size = ViewGroup.LayoutParams.MATCH_PARENT;
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(size, size);
if (mParent instanceof ViewPager) {
// ViewPager vp = (ViewPager) mParent;
// int position = vp.getCurrentItem();
// View child = vp.getChildAt(position);
// L.d(TAG, "hashcode ==> " + child.hashCode());
View child = mRootView;
if (child != null) {
if (child instanceof LinearLayout) {
LinearLayout ll = (LinearLayout) child;
ll.removeView(mTempView);
ll.addView(mTempView, 0, lp);
} else if (child instanceof RelativeLayout || child instanceof FrameLayout) {
ViewGroup vg = (ViewGroup) child;
vg.removeView(mTempView);
vg.addView(mTempView, lp);
} else {
L.e(TAG, "框架的填充只支持,LinearLayout、RelativeLayout、FrameLayout");
}
}
} else {
mParent.removeView(mTempView);
mParent.addView(mTempView, lp);
}
}
}
public void removeLayoutChildView(View v) {
if (v == null) return;
View view = getChildAt(0);
if (view != null) {
if (view instanceof LinearLayout) {
LinearLayout layout = (LinearLayout) view;
layout.removeView(v);
}
}
}
@Override
public void onRemoteUserLeft(String userId, RongCallCommon.CallDisconnectedReason reason) {
//incoming状态,localViewUserId为空
if (localViewUserId == null)
return;
if (localViewUserId.equals(userId)) {
localViewContainer.removeAllViews();
String currentUserId = RongIMClient.getInstance().getCurrentUserId();
FrameLayout remoteVideoView = (FrameLayout) remoteViewContainer.findViewWithTag(currentUserId);
localView = (SurfaceView) remoteVideoView.getChildAt(0);
remoteVideoView.removeAllViews();
localViewContainer.addView(localView);
TextView topUserNameView = (TextView) topContainer.findViewById(R.id.rc_voip_user_name);
UserInfo userInfo = RongContext.getInstance().getUserInfoFromCache(currentUserId);
if (userInfo != null) {
topUserNameView.setText(userInfo.getName());
} else {
topUserNameView.setText(currentUserId);
}
localViewUserId = currentUserId;
}
View singleRemoteView = remoteViewContainer.findViewWithTag(userId + "view");
if (singleRemoteView == null)
return;
LinearLayout container = (LinearLayout) singleRemoteView.getParent();
container.removeView(singleRemoteView);
if (container.equals(remoteViewContainer2)) {
if (remoteViewContainer1.getChildCount() > 0) {
View childView = remoteViewContainer1.getChildAt(0);
remoteViewContainer1.removeView(childView);
remoteViewContainer2.addView(childView);
}
}
}
public void removeFromLayout(@NonNull LinearLayout parent)
{
if (layout != null)
parent.removeView(layout);
}
/**
* Reorder the date picker spinners to match the order suggested by the locale.
* Assumes that the order of month and year in the locale is also the right order
* for the spinner columns.
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void reorderSpinners() {
boolean posInserted = false;
boolean yearInserted = false;
LinearLayout pickers = (LinearLayout) findViewById(R.id.pickers);
pickers.removeView(mPositionInYearSpinner);
pickers.removeView(mYearSpinner);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
// logic duplicated from android.widget.DatePicker
String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), "yyyyMMMdd");
for (int i = 0; i < pattern.length(); ++i) {
char ch = pattern.charAt(i);
if (ch == '\'') {
i = pattern.indexOf('\'', i + 1);
if (i == -1) {
throw new IllegalArgumentException("Bad quoting in " + pattern);
}
} else if ((ch == 'M' || ch == 'L') && !posInserted) {
pickers.addView(mPositionInYearSpinner);
posInserted = true;
} else if (ch == 'y' && !yearInserted) {
pickers.addView(mYearSpinner);
yearInserted = true;
}
}
} else {
// This method was used to order android.widget.DatePicker
// fields in JB prior to the availability of
// getBestDateTimePattern.
char[] order = DateFormat.getDateFormatOrder(getContext());
for (int i = 0; i < order.length; ++i) {
if (order[i] == 'M') {
pickers.addView(mPositionInYearSpinner);
posInserted = true;
} else if (order[i] == 'y') {
pickers.addView(mYearSpinner);
yearInserted = true;
}
}
}
if (!posInserted) pickers.addView(mPositionInYearSpinner);
if (!yearInserted) pickers.addView(mYearSpinner);
}
public void handleMessage(Message msg) {
if (msg.what == 1) {
String url = (String) msg.obj;
int length = msg.arg1;
ProgressBar bar = ProgressBars.get(url);
if (bar != null) {
// 设置进度条按读取的length长度更新
bar.incrementProgressBy(length);
if (bar.getProgress() == bar.getMax()) {
notificationManager.cancel(notificationId);
btnDownload.setText("下载");
// 下载完成后清除进度条并将map中的数据清空
LinearLayout layout = (LinearLayout) bar.getParent();
layout.removeView(bar);
ProgressBars.remove(url);
downloaders.get(url).delete(url);
downloaders.get(url).reset();
downloaders.remove(url);
new AlertDialog.Builder(BookOnlineActivity.this).setTitle("提示").setMessage("下载完成,是否将《"+bookNames[currentPosition]+"》加入书架?")
.setPositiveButton("加入", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
if(BookUtil.isExist( DbDataOperation.getBookInfo(resolver), SD_PATH+bookNames[currentPosition]+".txt")==true)
{
new AlertDialog.Builder(BookOnlineActivity.this).setTitle("提示").setMessage("此书在书架中已存在,无需继续添加!").setPositiveButton("确定", null).show();
}
else
{
DbDataOperation.insertToBookInfo(resolver, bookNames[currentPosition], "未知", SD_PATH+bookNames[currentPosition]+".txt", TimeUtil.getCurrentTime(),
TimeUtil.getCurrentTime(), 0, "未分类",BookUtil.getBookSize(SD_PATH+bookNames[currentPosition]+".txt"), "0.0%");
MainTabActivity.thMain.setCurrentTabByTag(MainTabActivity.TAB_BOOKSHELF);
}
}
}).setNegativeButton("取消", null).show();
}
}
}
}
public void setStyle(Context context, int clockStyle, float textSize, int textColor, boolean showAmPm, Typeface font) {
LinearLayout clockWrapper = (LinearLayout) findViewById(R.id.clock_wrapper);
analogClock = (CustomAnalogClock) clockWrapper.findViewById(R.id.custom_analog_clock);
ViewGroup.LayoutParams lp = clockWrapper.findViewById(R.id.custom_analog_clock).getLayoutParams();
float clockSize = textSize < 80 ? textSize : 80;
lp.height = (int) (clockSize * 10);
lp.width = (int) (clockSize * 9.5);
switch (clockStyle) {
case DISABLED:
removeView(clockWrapper);
break;
case DIGITAL_CLOCK:
textClock = (KillableTextClock) clockWrapper.findViewById(R.id.digital_clock);
textClock.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
textClock.setTextColor(textColor);
if (!showAmPm)
textClock.setFormat12Hour("h:mm");
if (Utils.isAndroidNewerThanN()) {
textClock.setTextLocale(context.getResources().getConfiguration().getLocales().get(0));
} else {
textClock.setTextLocale(context.getResources().getConfiguration().locale);
}
textClock.setTypeface(font);
clockWrapper.removeView(clockWrapper.findViewById(R.id.custom_analog_clock));
clockWrapper.removeView(clockWrapper.findViewById(R.id.s7_digital));
break;
case ANALOG_CLOCK:
clockWrapper.removeView(clockWrapper.findViewById(R.id.digital_clock));
clockWrapper.removeView(clockWrapper.findViewById(R.id.s7_digital));
clockWrapper.findViewById(R.id.custom_analog_clock).setLayoutParams(lp);
analogClock.init(context, R.drawable.default_face, R.drawable.default_hour_hand, R.drawable.default_minute_hand, 225, false, false);
break;
case ANALOG24_CLOCK:
clockWrapper.removeView(clockWrapper.findViewById(R.id.digital_clock));
clockWrapper.removeView(clockWrapper.findViewById(R.id.s7_digital));
clockWrapper.findViewById(R.id.custom_analog_clock).setLayoutParams(lp);
analogClock.init(context, R.drawable.clock_face, R.drawable.hour_hand, R.drawable.minute_hand, 0, true, false);
break;
case S7_CLOCK:
clockWrapper.removeView(clockWrapper.findViewById(R.id.digital_clock));
clockWrapper.removeView(clockWrapper.findViewById(R.id.s7_digital));
clockWrapper.findViewById(R.id.custom_analog_clock).setLayoutParams(lp);
analogClock.init(context, R.drawable.s7_face, R.drawable.s7_hour_hand, R.drawable.s7_minute_hand, 0, false, false);
break;
case PEBBLE_CLOCK:
clockWrapper.removeView(clockWrapper.findViewById(R.id.digital_clock));
clockWrapper.removeView(clockWrapper.findViewById(R.id.s7_digital));
clockWrapper.findViewById(R.id.custom_analog_clock).setLayoutParams(lp);
analogClock.init(context, R.drawable.pebble_face, R.drawable.pebble_hour_hand, R.drawable.pebble_minute_hand, 225, false, true);
break;
case S7_DIGITAL:
clockWrapper.removeView(clockWrapper.findViewById(R.id.digital_clock));
clockWrapper.removeView(clockWrapper.findViewById(R.id.custom_analog_clock));
if (textSize > 90)
textSize = 90;
Prefs prefs = new Prefs(context);
prefs.apply();
if (textSize < 50 && prefs.batteryStyle == 1)
textSize = 50;
digitalS7 = (DigitalS7) findViewById(R.id.s7_digital);
digitalS7.init(font, textSize, textColor);
break;
case FLAT_CLOCK:
clockWrapper.removeView(clockWrapper.findViewById(R.id.digital_clock));
clockWrapper.removeView(clockWrapper.findViewById(R.id.s7_digital));
clockWrapper.findViewById(R.id.custom_analog_clock).setLayoutParams(lp);
analogClock.init(context, R.drawable.flat_face, R.drawable.flat_hour_hand, R.drawable.flat_minute_hand, 235, false, false);
break;
case FLAT_RED_CLOCK:
clockWrapper.removeView(clockWrapper.findViewById(R.id.digital_clock));
clockWrapper.removeView(clockWrapper.findViewById(R.id.s7_digital));
clockWrapper.findViewById(R.id.custom_analog_clock).setLayoutParams(lp);
analogClock.init(context, R.drawable.flat_face, R.drawable.flat_red_hour_hand, R.drawable.flat_red_minute_hand, 0, false, false);
break;
case FLAT_STANDARD_TICKS:
clockWrapper.removeView(clockWrapper.findViewById(R.id.digital_clock));
clockWrapper.removeView(clockWrapper.findViewById(R.id.s7_digital));
clockWrapper.findViewById(R.id.custom_analog_clock).setLayoutParams(lp);
analogClock.init(context, R.drawable.standard_ticks_face, R.drawable.hour_hand, R.drawable.minute_hand, 0, false, false);
break;
}
}
private void addLayoutTime(VH holder) {
LinearLayout ll_containerTime = (LinearLayout) holder.itemView.findViewById(R.id.contentContainer).getParent();
if (holder.itemView.findViewById(R.id.csl_ll_time) != null) {
ll_containerTime.removeView(holder.itemView.findViewById(R.id.csl_ll_time));
}
ll_containerTime.addView(ViewMaker.getViewTime(), new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}