AJW
AJW

Reputation: 1649

Android Parent View: How do I reduce by the size of the Toolbar?

I've set up a new android Toolbar with:

android:layout_height="?attr/actionBarSize"

The toolbar appears correctly at the top of the screen. The problem I'm having is that the top of the background image for the remainder of the app screen is being covered over by toolbar. I need to reduce the height of the container that holds the background image by the height of the toolbar in my layout file but am not having any luck.

The toolbar is showing correctly. It has an image as a background.

Here is the main.xml file:

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/big_wave"
tools:context=".MainActivity" >

<android.support.v7.widget.Toolbar

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_height="?attr/actionBarSize"
    android:layout_width="match_parent"
    android:background="@drawable/actionbar_skypic" />


</RelativeLayout>

Upvotes: 1

Views: 363

Answers (2)

Nauman Afzaal
Nauman Afzaal

Reputation: 1046

You can use android:layout_below property

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimaryDark" />

        <com.example.sample.SlidingTabLayout
                android:id="@+id/sliding_tabs"
                android:background="?attr/colorPrimaryDark"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="0px"
                android:layout_weight="1"
                android:background="@android:color/white" />
        </LinearLayout>

Here is the output.enter image description here

You can see below toolbar there is sliding layout tabs

Upvotes: 0

user2320244
user2320244

Reputation:

You can adjust the height of the image yourself, can't you? Or you can set the tool baar background as translucent or transparent.

toolbar.getBackground().setAlpha(0);

Upvotes: 1

Related Questions