I’m trying to make a control that is a composition of another controls. I’ve tried many ways but none seems to work… You ask why do I need that? Becaused
- I’ve faced the impossibility of creating a TextView with
different colors of shadow and gradient foreground -
I want to make
a volume text and it’s going to be presented by this custom controlspublic class MainMenuItem extends View { private MainMenuItemHelper firstLayerItem; private MainMenuItemHelper secondLayerItem; ... @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); secondLayerItem.draw(canvas); firstLayerItem.draw(canvas); } } public class MainMenuItemHelper extends TextView { private List<DrawCommand> commands; ... @Override protected void onDraw(Canvas canvas) { for (DrawCommand command : commands) { command.draw(canvas, getPaint()); super.onDraw(canvas); } } }
You need at least a Layout like
RelativeLayoutorLinearLayoutas a View can’t contain another View. You need aViewGroupinstead.I don’t know where and how you want to place it but the easiest way is to simply make a xml file containing your controls and style them like you would normally do.
A shadow color can be defined by
android:shadowColorto have a shadow for your text.Making the text itself being a gradient might be very tricky.