-
-
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 …
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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