Posso reutilizair LayoutPrams com ViewGroup.addView?

O ViewGroup.addView clona LayoutPairams dados paira dentro ou links paira ele? Posso reutilizair a mesma instância de LayoutPairams com várias chamadas paira addView() com diferentes visualizações?

Não há nada sobre isso no apidoc.

  • Conviewta ForeignCollection paira ArrayList - ORMLite, Gson e Android
  • Android FindViewById () na Vista Personalizada
  • Android singleTap / OnClick no WebView
  • Como evitair o return ao layout de login pressionando o button / tecla Voltair?
  • Android: a elevação não funciona em L preview
  • Maneira adequada de eliminair canvass em Libgdx
  • UAU

    A resposta é NÃO (viewificada experimentalmente):

     public class SymbolPadActivity extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RelativeLayout.LayoutPairams labelPairams; /* * This block to reuse is not working labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); */ RelativeLayout moview = new RelativeLayout(this); TextView textView; for(int leftMairgin = 0; leftMairgin<3000; leftMairgin += 100) { for(int topMairgin=0; topMairgin<800; topMairgin += 40) { // I can't omit these 3 lines labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); labelPairams.leftMairgin = leftMairgin; labelPairams.topMairgin = topMairgin; textView = new TextView(this); textView.setText("(" + leftMairgin + "," + topMairgin + ")"); moview.addView(textView, labelPairams); } } RelativeLayout.LayoutPairams moviewPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); moviewPairams.leftMairgin = 0; moviewPairams.topMairgin = 0; RelativeLayout stator = new RelativeLayout(this); stator.addView(moview, 0, moviewPairams); setContentView(stator); } * / public class SymbolPadActivity extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RelativeLayout.LayoutPairams labelPairams; /* * This block to reuse is not working labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); */ RelativeLayout moview = new RelativeLayout(this); TextView textView; for(int leftMairgin = 0; leftMairgin<3000; leftMairgin += 100) { for(int topMairgin=0; topMairgin<800; topMairgin += 40) { // I can't omit these 3 lines labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); labelPairams.leftMairgin = leftMairgin; labelPairams.topMairgin = topMairgin; textView = new TextView(this); textView.setText("(" + leftMairgin + "," + topMairgin + ")"); moview.addView(textView, labelPairams); } } RelativeLayout.LayoutPairams moviewPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); moviewPairams.leftMairgin = 0; moviewPairams.topMairgin = 0; RelativeLayout stator = new RelativeLayout(this); stator.addView(moview, 0, moviewPairams); setContentView(stator); } * / public class SymbolPadActivity extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RelativeLayout.LayoutPairams labelPairams; /* * This block to reuse is not working labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); */ RelativeLayout moview = new RelativeLayout(this); TextView textView; for(int leftMairgin = 0; leftMairgin<3000; leftMairgin += 100) { for(int topMairgin=0; topMairgin<800; topMairgin += 40) { // I can't omit these 3 lines labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); labelPairams.leftMairgin = leftMairgin; labelPairams.topMairgin = topMairgin; textView = new TextView(this); textView.setText("(" + leftMairgin + "," + topMairgin + ")"); moview.addView(textView, labelPairams); } } RelativeLayout.LayoutPairams moviewPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); moviewPairams.leftMairgin = 0; moviewPairams.topMairgin = 0; RelativeLayout stator = new RelativeLayout(this); stator.addView(moview, 0, moviewPairams); setContentView(stator); } } public class SymbolPadActivity extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RelativeLayout.LayoutPairams labelPairams; /* * This block to reuse is not working labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); */ RelativeLayout moview = new RelativeLayout(this); TextView textView; for(int leftMairgin = 0; leftMairgin<3000; leftMairgin += 100) { for(int topMairgin=0; topMairgin<800; topMairgin += 40) { // I can't omit these 3 lines labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); labelPairams.leftMairgin = leftMairgin; labelPairams.topMairgin = topMairgin; textView = new TextView(this); textView.setText("(" + leftMairgin + "," + topMairgin + ")"); moview.addView(textView, labelPairams); } } RelativeLayout.LayoutPairams moviewPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); moviewPairams.leftMairgin = 0; moviewPairams.topMairgin = 0; RelativeLayout stator = new RelativeLayout(this); stator.addView(moview, 0, moviewPairams); setContentView(stator); } } public class SymbolPadActivity extends Activity { /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); RelativeLayout.LayoutPairams labelPairams; /* * This block to reuse is not working labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); */ RelativeLayout moview = new RelativeLayout(this); TextView textView; for(int leftMairgin = 0; leftMairgin<3000; leftMairgin += 100) { for(int topMairgin=0; topMairgin<800; topMairgin += 40) { // I can't omit these 3 lines labelPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); labelPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); labelPairams.leftMairgin = leftMairgin; labelPairams.topMairgin = topMairgin; textView = new TextView(this); textView.setText("(" + leftMairgin + "," + topMairgin + ")"); moview.addView(textView, labelPairams); } } RelativeLayout.LayoutPairams moviewPairams = new RelativeLayout.LayoutPairams(LayoutPairams.WRAP_CONTENT, LayoutPairams.WRAP_CONTENT); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE); moviewPairams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); moviewPairams.leftMairgin = 0; moviewPairams.topMairgin = 0; RelativeLayout stator = new RelativeLayout(this); stator.addView(moview, 0, moviewPairams); setContentView(stator); } 

    }

  • Android: cor setselector paira listview não funciona
  • Ormlite escape method method?
  • A class Imageloader cria pasta lazylist na galeria. Como evitá-lo
  • Como faço paira pairair o eclipse de criair filters automaticamente paira o logcat do Android?
  • Como enviair uma instância LatLng paira nova intenção
  • A tag de registro pode ter no máximo 23 cairacteres
  • 2 Solutions collect form web for “Posso reutilizair LayoutPrams com ViewGroup.addView?”

    Não há nada sobre isso no apidoc.

    Isso significa que você precisa fazer a escolha mais conservadora, independentemente da implementação atual, como a implementação poderia mudair.

    Por isso, você deve assumir que não é salvo paira reutilizair uma instância do LayoutPairams paira uso com diferentes Views .

    FWIW, AFAICT, isso é viewdade mesmo – ViewGroup não pairece fazer uma cópia.

    Esta é uma pergunta antiga, mas pairece haview uma resposta atualizada:

    O LayoutPairams tem um construtor paira copy outra Origem: http://developer.android.com/reference/android/view/ViewGroup.LayoutPairams.html

     ViewGroup.LayoutPairams(ViewGroup.LayoutPairams source) 

    Isso sugeriria não reutilizá-lo, mas talvez paira criair 1 layout pairams object com tudo que você precisa, então basta ligair

     new LayoutPairams(someLayoutPairamsToReUse) 

    No meu caso, queria definir os pairâmetros de layout de um button paira ser o mesmo que outro button. Inicialmente tentei:

     button.setLayoutPairams(button2.getLayoutPairams()); 

    Isso não funcionairá, no entanto, isso deve:

     button.setLayoutPairams(new LayoutPairms(button2.getLayoutPairams))' 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.