Reputation: 179
I am adding a ConstraintLayout to a LinearLayout with a toolbar. Adding the ConstraintLayout causes the toolbar to no longer be visible, and the Layout Inspector shows that the toolbar has visibility GONE
though the debugger shows VISIBLE
. Am I missing something here? Using LayoutParams.WRAP_CONTENT
doesn't work either.
protected void setView(View view) {
super.setContentView(R.layout.content_view);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
LinearLayout layout = findViewById(R.id.linear_layout);
layout.addView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
content_view.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linear_layout"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
</LinearLayout>
view being passed in:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/white">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 0
Views: 253
Reputation: 26
You have a few things that you may be missing.
<include layout="@layout/[NAME_OF_THE_VIEW_LAYOUT]"/>
and comment out the java code - just to be sure.Upvotes: 1