What's wrong with my include in RelativeLayout?

前端 未结 2 1461
栀梦
栀梦 2021-02-13 00:49

I want to create an activity with a title bar at top and a navigation bar at bottom. I used include to include the title bar layout and the navigation bar layout in

相关标签:
2条回答
  • 2021-02-13 01:25

    You have nothing to fill the space between the top and bottom bar by the looks of it.

    As a side not I tend to use LinearLayout instead and use the layout_weight attribute in the following way;

    title_bar & navigation_bar get layout_weight="0" and the content between the two gets layout_weight="1". This tells the layout manager to expand the content to fill the space between the two if your linear layout is;

    title_bar content navigation_bar

    0 讨论(0)
  • 2021-02-13 01:29

    In order to override the attributes of the layout you're including, you must also override both the layout width and layout height. If both of those settings are not overridden, any other layout changes you try will be ignored.

    Your layout above

    <include android:id="@+id/title_bar" layout="@layout/title_bar" 
        android:layout_alignParentTop="true"
    />
    <include android:id="@+id/navigation_bar" layout="@layout/navigation_bar" 
        android:layout_alignParentBottom="true"/>
    

    Should actually be with a wrap content or fill parent, as appropriate.

    <include android:id="@+id/navigation_bar" layout="@layout/navigation_bar"  android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>
    
    0 讨论(0)
提交回复
热议问题