下面列出了android.view.ViewGroup#removeViews ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void destroyView(View rootView) {
try {
if (rootView instanceof ViewGroup) {
ViewGroup cViewGroup = ((ViewGroup) rootView);
for (int index = 0; index < cViewGroup.getChildCount(); index++) {
destroyView(cViewGroup.getChildAt(index));
}
cViewGroup.removeViews(0, ((ViewGroup) rootView).getChildCount());
// Ensure that the viewgroup's status to be normal
WXReflectionUtils.setValue(rootView, "mChildrenCount", 0);
}
if(rootView instanceof Destroyable){
((Destroyable)rootView).destroy();
}
} catch (Exception e) {
WXLogUtils.e("WXSDKInstance destroyView Exception: ", e);
}
}
private void destroyView(View rootView) {
try {
if (rootView instanceof ViewGroup) {
ViewGroup cViewGroup = ((ViewGroup) rootView);
for (int index = 0; index < cViewGroup.getChildCount(); index++) {
destroyView(cViewGroup.getChildAt(index));
}
cViewGroup.removeViews(0, ((ViewGroup) rootView).getChildCount());
// Ensure that the viewgroup's status to be normal
WXReflectionUtils.setValue(rootView, "mChildrenCount", 0);
}
if(rootView instanceof Destroyable){
((Destroyable)rootView).destroy();
}
} catch (Exception e) {
WXLogUtils.e("WXSDKInstance destroyView Exception: ", e);
}
}
private void destroyView(View rootView) {
try {
if (rootView instanceof ViewGroup) {
ViewGroup cViewGroup = ((ViewGroup) rootView);
for (int index = 0; index < cViewGroup.getChildCount(); index++) {
destroyView(cViewGroup.getChildAt(index));
}
cViewGroup.removeViews(0, ((ViewGroup) rootView).getChildCount());
// Ensure that the viewgroup's status to be normal
WXReflectionUtils.setValue(rootView, "mChildrenCount", 0);
}
} catch (Exception e) {
WXLogUtils.e("WXSDKInstance destroyView Exception: " + WXLogUtils.getStackTrace(e));
}
}
public static void unmount(View v, boolean removeChildren) {
Mount m = mounts.get(v);
if (m != null) {
mounts.remove(v);
if (v instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) v;
int childCount = viewGroup.getChildCount();
for (int i = 0; i < childCount; i++) {
unmount(viewGroup.getChildAt(i));
}
if (removeChildren) {
viewGroup.removeViews(0, childCount);
}
}
}
}
public static void loadSnapshotsIntoList(
ViewGroup valuesList, Label label, AppAccount appAccount) {
Context context = valuesList.getContext();
SnapshotLabelValue snapshotLabelValue = label.getSnapshotLabelValue();
valuesList.setVisibility(View.VISIBLE);
// Make sure it has the correct number of views, re-using as many as possible.
int childCount = valuesList.getChildCount();
int snapshotsCount = snapshotLabelValue.getSnapshotsCount();
if (childCount < snapshotsCount) {
for (int i = 0; i < snapshotsCount - childCount; i++) {
LayoutInflater.from(context).inflate(R.layout.snapshot_value_details, valuesList);
}
} else if (childCount > snapshotsCount) {
valuesList.removeViews(0, childCount - snapshotsCount);
}
SensorAppearanceProvider sensorAppearanceProvider =
AppSingleton.getInstance(context).getSensorAppearanceProvider(appAccount);
String valueFormat = context.getResources().getString(R.string.data_with_units);
for (int i = 0; i < snapshotsCount; i++) {
GoosciSnapshotValue.SnapshotLabelValue.SensorSnapshot snapshot =
snapshotLabelValue.getSnapshots(i);
ViewGroup snapshotLayout = (ViewGroup) valuesList.getChildAt(i);
GoosciSensorAppearance.BasicSensorAppearance appearance =
snapshot.getSensor().getRememberedAppearance();
TextView sensorName = (TextView) snapshotLayout.findViewById(R.id.sensor_name);
sensorName.setCompoundDrawablesRelative(null, null, null, null);
sensorName.setText(appearance.getName());
String value =
BuiltInSensorAppearance.formatValue(
snapshot.getValue(), appearance.getPointsAfterDecimal());
((TextView) snapshotLayout.findViewById(R.id.sensor_value))
.setText(String.format(valueFormat, value, appearance.getUnits()));
loadLargeDrawable(appearance, sensorAppearanceProvider, snapshotLayout, snapshot.getValue());
}
}
static void setPreviewColor(View preferenceView, int color, boolean isEnabled) {
if (preferenceView != null && preferenceView instanceof ViewGroup) {
Context context = preferenceView.getContext();
ViewGroup widgetFrameView = ((ViewGroup) preferenceView.findViewById(android.R.id.widget_frame));
if (widgetFrameView != null) {
ColorPickerPreferenceWidget widgetView = null;
// find already created preview image
int count = widgetFrameView.getChildCount();
for (int i = 0; i < count; i++) {
View view = widgetFrameView.getChildAt(i);
if (view instanceof ColorPickerPreferenceWidget && IMAGE_VIEW_TAG.equals(view.getTag())) {
widgetView = (ColorPickerPreferenceWidget) view;
break;
}
}
if (widgetView == null) {
// remove already created preview image and create new one
if (count > 0)
widgetFrameView.removeViews(0, count);
widgetView = new ColorPickerPreferenceWidget(context);
widgetView.setTag(IMAGE_VIEW_TAG);
widgetFrameView.setVisibility(View.VISIBLE);
widgetFrameView.setPadding(
widgetFrameView.getPaddingLeft(),
widgetFrameView.getPaddingTop(),
(int) (Util.getDisplayDensity(context) * 8),
widgetFrameView.getPaddingBottom()
);
widgetFrameView.addView(widgetView);
}
// determine and set colors
int borderColor = Color.WHITE;
if (!isEnabled) {
color = reduceBrightness(color, 1);
borderColor = reduceBrightness(borderColor, 1);
}
widgetView.setColor(color, borderColor);
}
}
}