Skip to content

Instantly share code, notes, and snippets.

  • Save GameCore/5fcb3b17cbb2537ca17f to your computer and use it in GitHub Desktop.
Save GameCore/5fcb3b17cbb2537ca17f to your computer and use it in GitHub Desktop.
Una cosa que hay que tener muy clara del método inflate(), que pertenece al objeto de la clase LayoutInflater, es –lo que lleva demasiado a confusión- que inflar no se refiere a insertar unas Views en un ViewGroup, sino a poner los atributos de diseño del que podría ser el ViewGroup padre. Aquí seguramente surja la duda ¿Pero si cuando inflo se …
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fichero_de_disenio);
RelativeLayout contenedor = (RelativeLayout) findViewById(R.id.RelativeLayout_contenedor);
LayoutInflater inflater = LayoutInflater.from(this);
View laViewInflada = inflater.inflate(R.layout.adjuntar_en_un_viewgroup, contenedor, true);
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/otra_view" />
<RelativeLayout
android:id="@+id/RelativeLayout_contenedor"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:orientation="vertical" >
</RelativeLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/otro_fichero_de_dise_o_xml"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment