0

I understand that XML templates in Android generally have static elements and that's pretty much the point of them to layout the page, but I am designing an app that has the same elements on every page, except for a varying number of buttons at the bottom depending on what data is being displayed.

Now, I could (and have so far) simply make 5 different XML templates each with one additional button element added so I can display 1 to 5 buttons and call the appropriate template depending on what is required, but that seems terribly inelegant to me. It works though. I just feel like I must be missing something since I am new to this platform and XML templating in general.

To be specific, given the above background: Is there any way I could use a single template and have it use a varying number of buttons at the end? I have been cautioned against implementing layouts both programmatically in java and in XML, but might this be an exception to that rule? And if so how would I go about it?

Please let me know if any more information is needed to answer this question. As it is a fairly general question, I didn't include any code, but will provide it if necessary. Thank you!

4

1 回答 1

0

您可以在底部放置任意数量的按钮。然后在每个活动中,您访问每个按钮,然后调用:

buttonX.setVisibility(View.GONE);

对于您在该视图中不需要的那些。

于 2013-10-21T02:48:46.527 回答