Search code examples
androidandroid-toolbar

Toolbar covering relative layout


My toolbar is covering parts of the relative layout below see pic

enter image description here I have tried all the constraints I could think off but I cant seem to get it right

Layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackground"
    tools:context="husforbi.com.accenture.husforbi.HomeActivity"
    tools:layout_editor_absoluteY="81dp">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"></android.support.v7.widget.Toolbar>

<RelativeLayout
    android:id="@+id/relativeLayout2"
    android:layout_width="match_parent"
    android:layout_height="105dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="80dp"
    android:background="@color/colorPrimary"
    app:layout_constraintBottom_toTopOf="@+id/relativeLayout"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@id/toolbar"
    app:layout_constraintTop_toBottomOf="@id/toolbar"
    android:layout_below="@id/toolbar">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:id="@+id/sellername"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginStart="14dp"
        android:layout_toEndOf="@+id/imageView2"

        android:textColor="@color/colorPrimaryDark"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/sellerid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/sellername"
        android:layout_below="@+id/sellername"
        android:textColor="@color/colorPrimaryDark" />

</RelativeLayout>

<RelativeLayout
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="154dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@color/colorPrimary"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/relativeLayout2">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/Newspaper_tag"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/newsCount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textAlignment="textEnd"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="18sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="50dp"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/Calendar_tag"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/calCount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textAlignment="textEnd"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="18sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

        <Button
            android:id="@+id/suggest"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@android:color/holo_blue_light"
            android:text="@string/Fix_tag"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/rate"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@android:color/holo_blue_dark"
            android:text="@string/Update_tag"
            android:textColor="@android:color/background_light" />
    </LinearLayout>
</RelativeLayout>

<ProgressBar
    android:id="@+id/indeterminateBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:visibility="invisible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/relativeLayout" />

I am using an AppCompatDelegate to create the toolbar, doubt that changes anything but it looks like this:

public class HomeActivity extends Activity implements View.OnClickListener, AppCompatCallback {

ProgressBar spinner;

private AppCompatDelegate delegate;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    delegate = AppCompatDelegate.create(this, this);

    //call the onCreate() of the AppCompatDelegate
    delegate.onCreate(savedInstanceState);

    //use the delegate to inflate the layout
    delegate.setContentView(R.layout.activity_home);

    //add the Toolbar
    Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
    delegate.setSupportActionBar(toolbar);
    toolbar.setTitle(R.string.HomeActivity);
    delegate.getSupportActionBar().setDisplayShowTitleEnabled(true);
    delegate.getSupportActionBar().setDisplayShowHomeEnabled(true);
    delegate. getSupportActionBar().setIcon(R.mipmap.ic_launcher);

Finally the theme of the activity looks like this:

<activity
    android:name=".HomeActivity"
    android:parentActivityName=".BarcodeCaptureActivity"
    android:theme="@style/AppTheme.NoActionBar" />

Any help is much appreaciated.

Thank you!


Solution

  • try this solution with RelativeLayout :

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        tools:context="husforbi.com.accenture.husforbi.HomeActivity"
        tools:layout_editor_absoluteY="81dp">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
    
        <RelativeLayout
            android:id="@+id/relativeLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            android:layout_below="@id/toolbar">
    
            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                app:srcCompat="@mipmap/ic_launcher_round" />
    
            <TextView
                android:id="@+id/sellername"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginStart="14dp"
                android:layout_toEndOf="@+id/imageView2"
    
                android:textColor="@color/colorPrimaryDark"
                android:textSize="18sp" />
    
            <TextView
                android:id="@+id/sellerid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignStart="@+id/sellername"
                android:layout_below="@+id/sellername"
                android:textColor="@color/colorPrimaryDark" />
    
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/relativeLayout"
            android:layout_width="match_parent"
            android:layout_height="154dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:background="@color/colorPrimary"
            android:layout_below="@+id/relativeLayout2">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginTop="8dp"
                android:orientation="horizontal">
    
                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/Newspaper_tag"
                    android:textColor="@color/colorPrimaryDark"
                    android:textSize="18sp" />
    
                <TextView
                    android:id="@+id/newsCount"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textAlignment="textEnd"
                    android:textColor="@color/colorPrimaryDark"
                    android:textSize="18sp" />
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginTop="50dp"
                android:orientation="horizontal">
    
                <TextView
                    android:id="@+id/textView6"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="@string/Calendar_tag"
                    android:textColor="@color/colorPrimaryDark"
                    android:textSize="18sp" />
    
                <TextView
                    android:id="@+id/calCount"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textAlignment="textEnd"
                    android:textColor="@color/colorPrimaryDark"
                    android:textSize="18sp" />
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:orientation="horizontal">
    
                <Button
                    android:id="@+id/suggest"
                    android:layout_width="0dp"
                    android:layout_height="50dp"
                    android:layout_weight="1"
                    android:background="@android:color/holo_blue_light"
                    android:text="@string/Fix_tag"
                    android:textColor="@android:color/background_light" />
    
                <Button
                    android:id="@+id/rate"
                    android:layout_width="0dp"
                    android:layout_height="50dp"
                    android:layout_weight="1"
                    android:background="@android:color/holo_blue_dark"
                    android:text="@string/Update_tag"
                    android:textColor="@android:color/background_light" />
            </LinearLayout>
        </RelativeLayout>
    
        <ProgressBar
            android:id="@+id/indeterminateBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:visibility="invisible"
            android:layout_below="@+id/relativeLayout"
            android:layout_centerHorizontal="true"/>
    
    </RelativeLayout>