android layout with fragment breaks when toolbar is there -
couldn't find more appropriate title problem following. have linearlayout
contains linearlayout
, fragment. want add toolbar
when so, see toolbar
, other screen white.
here layout:
<?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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context="xeniasis.mymarket.mainactivity"> <include android:id="@+id/toolbar" layout="@layout/toolbar" /> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:baselinealigned="false" android:weightsum="4"> <linearlayout android:id="@+id/categories_layout" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:paddingright="20dp"> <expandablelistview android:id="@+id/categories_listview" android:layout_width="match_parent" android:layout_height="match_parent" /> </linearlayout> <fragment android:id="@+id/mainpane" android:name="xeniasis.mymarket.products" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" tools:layout="@layout/activity_main" /> </linearlayout> </linearlayout>
toolbar:
<android.support.v7.widget.toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:elevation="4dp" android:padding="5dp" android:theme="@style/toolbartheme" />
and fragment
layout:
<?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:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="xeniasis.mymarket.mainactivity"> <android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.widget.swiperefreshlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swiperefreshcontainer" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="8dp" android:paddingright="8dp" android:paddingtop="@dimen/activity_vertical_margin"> <gridview android:id="@+id/productsgridview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_alignparenttop="true" android:numcolumns="3"></gridview> </android.support.v4.widget.swiperefreshlayout> <android.support.design.widget.floatingactionbutton android:id="@+id/settings" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|start" android:layout_margin="8dp" android:clickable="true" android:elevation="5dp" android:src="@android:drawable/ic_menu_search" /> </android.support.design.widget.coordinatorlayout> </linearlayout>
this happens when have fragment
, cause had same xml static layout fragment
now.
the problem used linearlayout with
android:orientation="horizontal"
and since toolbar has match_parent
width occupies screen. try use
android:orientation="vertical"
in root layout