Ответ 1
Я думаю, что вам нужно будет перебирать все виды в вашем макете, ища андроид: id, который вы хотите. Затем вы можете использовать View setVisibility() для изменения видимости. Вы также можете использовать View setTag()/getTag() вместо android: id, чтобы отметить просмотры, которые вы хотите обработать. Например, следующий код использует метод общего назначения для перемещения макета:
// Get the top view in the layout.
final View root = getWindow().getDecorView().findViewById(android.R.id.content);
// Create a "view handler" that will hide a given view.
final ViewHandler setViewGone = new ViewHandler() {
public void process(View v) {
// Log.d("ViewHandler.process", v.getClass().toString());
v.setVisibility(View.GONE);
}
};
// Hide any view in the layout whose Id equals R.id.textView1.
findViewsById(root, R.id.textView1, setViewGone);
/**
* Simple "view handler" interface that we can pass into a Java method.
*/
public interface ViewHandler {
public void process(View v);
}
/**
* Recursively descends the layout hierarchy starting at the specified view. The viewHandler's
* process() method is invoked on any view that matches the specified Id.
*/
public static void findViewsById(View v, int id, ViewHandler viewHandler) {
if (v.getId() == id) {
viewHandler.process(v);
}
if (v instanceof ViewGroup) {
final ViewGroup vg = (ViewGroup) v;
for (int i = 0; i < vg.getChildCount(); i++) {
findViewsById(vg.getChildAt(i), id, viewHandler);
}
}
}