Skip to content

Instantly share code, notes, and snippets.

@2tanayk
Last active February 5, 2022 21:28
Show Gist options
  • Save 2tanayk/4256001df6168740e641da482aed3a3b to your computer and use it in GitHub Desktop.
Save 2tanayk/4256001df6168740e641da482aed3a3b to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MyActivity">
<include layout="@layout/my_linear_layout" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="200dp"
android:gravity="center">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Activity"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
</LinearLayout>
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
LinearLayout parent = findViewById(R.id.linearLayout);
//by doing this we lose all our theme customisation
LayoutInflater layoutInflater = LayoutInflater.from(getApplicationContext());
View myLinearLayout = layoutInflater.inflate(R.layout.my_linear_layout, parent, false);
parent.addView(myLinearLayout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment