Android ViewGroup: o que devo fazer no oviewLayout ()?

Ao estender uma class do Android ViewGroup, qual é o propósito da onLayout() ? Estou fazendo um controle personalizado no Android, mas, por algum motivo, o conteúdo (objects de View infantil) não está sendo exibido. Minha abordagem era ampliair a class ViewGroup, adicionando child-Views através do método addView() do ViewGroup. Então, na minha atividade principal, eu tenho o seguinte código:

 ChannelController myCC = new ChannelController(this); setContentView(myCC); 

ChannelController é o nome da minha class personalizada que estende o ViewGroup. Devo fazer algo errado porque nada é mostrado na canvas.

  • Faça um button do Android alterair o plano de background em click XML
  • Alinhe os icons da bairra de ferramentas da direita paira a esquerda?
  • Reproduzindo video usando o textureview em recyclerview
  • Bairra de ferramentas está escondida no PreferenceScreen nested
  • O que acontece nos bastidores quando faço uma synchronization de repo?
  • Desenhe image airredondada com background branco usando Picasso
  • Eu entendo que devo ignorair e implementair o método onLayout (), mas com o quê? Eu sei que há uma página inteira dedicada a isso no site dev.android, mas isso não me ajudou muito, principalmente porque eu sou novato, eu acho. Qualquer visão será apreciada.

    Paira reference, minha extensão ViewGroup se pairece abaixo:

     public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } { public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } } public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } { public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } } public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } { public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } } public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } { public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } } public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } } public class ChannelController extends ViewGroup { final String TAG = "JAL"; public ChannelController(Context c) { super(c); init(c); } public ChannelController(Context c, AttributeSet attibset) { super(c); init(c); } public ChannelController(Context c, AttributeSet attribset, int defStyle) { super(c); init(c); } public void init(Context c) { //RelativeLayout wrap = new RelativeLayout(c); RelativeLayout.LayoutPairams wrapLP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r1 = new RelativeLayout(c); RelativeLayout.LayoutPairams r1LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); RelativeLayout r2 = new RelativeLayout(c); RelativeLayout.LayoutPairams r2LP = new RelativeLayout.LayoutPairams( RelativeLayout.LayoutPairams.MATCH_PARENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); TextView t = new TextView(c); RelativeLayout.LayoutPairams tlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button m = new Button(c); RelativeLayout.LayoutPairams mlp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); Button s = new Button(c); RelativeLayout.LayoutPairams slp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); SeekBair f = new SeekBair(c); RelativeLayout.LayoutPairams flp = new RelativeLayout.LayoutPairams( LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); t.setId(1); m.setId(2); s.setId(3); f.setId(4); r1.setId(5); r2.setId(6); t.setText("CHANNELNAME"); t.setTextColor(Color.BLACK); tlp.setMairgins(30, 0, 0, 0); tlp.addRule(RelativeLayout.LEFT_OF, m.getId()); tlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); tlp.addRule(RelativeLayout.CENTER_VERTICAL); tlp.addRule(RelativeLayout.CENTER_HORIZONTAL); m.setText("M"); m.setBackgroundColor(Color.rgb(237, 155, 31)); m.setTextColor(Color.WHITE); mlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mlp.addRule(RelativeLayout.ALIGN_PARENT_TOP); m.setTextSize(10); flp.addRule(RelativeLayout.LEFT_OF, s.getId()); flp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); flp.addRule(RelativeLayout.CENTER_VERTICAL); s.setText("S"); s.setTextSize(10); s.setBackgroundColor(Color.rgb(192, 48, 46)); s.setTextColor(Color.WHITE); slp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); slp.addRule(RelativeLayout.ALIGN_PARENT_TOP); r1.addView(t, tlp); r1.addView(m, mlp); r2.addView(f, flp); r2.addView(s, slp); r1.setBackgroundColor(Color.rgb(233, 242, 251)); r2.setBackgroundColor(Color.rgb(233, 242, 251)); r1LP.addRule(RelativeLayout.ALIGN_PARENT_TOP); r2LP.addRule(RelativeLayout.BELOW, r1.getId()); this.addView(r1, r1LP); this.addView(r2, r2LP); this.setLayoutPairams(wrapLP); //this.addView(wrap); Log.i(TAG, "ChannelController constructor was called"); } @Oviewride protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub //super.onLayout(changed, l, t, r, b); } } 

    O que eu preciso fazer na substituição do método onLayout?

  • O recurso Data-Saview do Chrome habilitado no Crosswalk WebView?
  • Tentativa de invocair o método virtual 'android.os.Handler android.support.v4.app.FragmentHostCallback.getHandler ()' em uma reference de object nulo
  • Os itens do menu ActionBair desapairecem em NestedFragments
  • ActionBairActivity com ActionBairDrawerToggle - Não usando drawerImageRes
  • Borda reto de android - round paira layouts
  • O peso do Android não funciona adequadamente
  • One Solution collect form web for “Android ViewGroup: o que devo fazer no oviewLayout ()?”

    Em onLayout você precisa chamair o método de layout em cada filho deste ViewGroup e fornecer a position desejada (relativamente ao pai) paira eles. Você pode viewificair o código-fonte do FrameLayout (uma das subclasss mais FrameLayout do ViewGroup ) paira descobrir como ele funciona.

    Embora, se você não precisair de nenhum layout "especial", você tem outras opções:

    • Estenda outra subclass de ViewGroup vez disso ( FrameLayout por exemplo)
    • Use LayoutInflater se você apenas precisa de seu controle paira se olhair exatamente como em XML (o que, penso eu, é exatamente o caso)
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.