0

I use Android Studio and I created the XML layouts file with it. Suprisingly the layouts in the emulator look different to the ones I created and I have no clue why this is happening. Here you see some pictures. Main Activity layout in Android Studio: enter image description here

Main Activity in the emulator (why is there the red marked text, which is not visible in the layout): enter image description here

Selection Activity in Android Studio: enter image description here

Selection Activity in in the emulator (1: Text is wrong, 2: the buttoms are not in the right place): enter image description here

Constrainets in Android Studioenter image description here

Here is the code for the Main activity:

<?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"


    tools:context=".MainActivity"
    tools:ignore="ExtraText">




    '<!--Learning: The following lines define a toolbar -->'

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_mainActivity"
        android:layout_width="match_parent"
        android:layout_height="53dp"
        android:background="#435cb53f"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:titleTextColor="@android:color/holo_green_light" />


    <Button
        android:id="@+id/Statistik_Button"
        android:layout_width="256dp"
        android:layout_height="95dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:background="#435cb53f"
        android:text="@string/Statistik_Button"
        android:textAllCaps="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.496"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.697" />

    <Button
        android:id="@+id/Bestellen_Button"
        android:layout_width="255dp"
        android:layout_height="96dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:background="#435cb53f"
        android:text="@string/Bestellen_Button"
        android:textAllCaps="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.279" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="153dp" />

    <TextView
        android:id="@+id/textView_ToolBar_MainActivity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="@string/Main_Activity_Toolbar_Text"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:visibility="visible"
        app:fontFamily="@font/roboto_bold"
        app:layout_constraintBottom_toBottomOf="@+id/toolbar_mainActivity"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.535"
        app:layout_constraintStart_toStartOf="@+id/toolbar_mainActivity"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.421"
        tools:text="App" />


</android.support.constraint.ConstraintLayout>

And here is the code for the selection activity:

<ScrollView 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"
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"


        tools:context=".MainActivity"
        tools:ignore="ExtraText">


        '<!--Learning: The following lines define a toolbar -->'

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_mainActivity"
            android:layout_width="match_parent"
            android:layout_height="53dp"
            android:background="#435cb53f"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:titleTextColor="@android:color/holo_green_light" />


        <TextView
            android:id="@+id/textView_ToolBar_CocktailSelectionActivity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="TestText"
            android:textColor="@android:color/white"
            android:textSize="24sp"
            android:visibility="visible"
            app:layout_constraintBottom_toBottomOf="@+id/toolbar_mainActivity"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.535"
            app:layout_constraintStart_toStartOf="@+id/toolbar_mainActivity"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.421"
            tools:text="Selection" />

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="1000dp"
            tools:ignore="MissingConstraints"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="73dp">


            <ImageButton
                android:id="@+id/imageButton"
                android:layout_width="210dp"
                android:layout_height="128dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.026"
                app:srcCompat="@mipmap/test_dish_2" />

            <ImageButton
                android:id="@+id/imageButton2"
                android:layout_width="210dp"
                android:layout_height="128dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.014"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.027"
                app:srcCompat="@mipmap/test_dish_1" />

            <ImageButton
                android:id="@+id/imageButton3"
                android:layout_width="210dp"
                android:layout_height="128dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.014"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.788"
                app:srcCompat="@mipmap/cocktail_x" />

        </android.support.constraint.ConstraintLayout>


    </android.support.constraint.ConstraintLayout>
</ScrollView>

Manifest-File (requested by Ronak):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.td.barapp">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />

        <activity android:name=".Selection_Activity"></activity>
    </application>

</manifest>

Update: Does anybody know a good tutorial for combining a ScrollView with a Constrained Layout? As posted before, the use of a "normal" Constrained Layout is quite simple and I do not have any problems with that. Things become extremely challenging for me when combining it with a Scroll View

VanessaF
  • 515
  • 11
  • 36
  • in the first image the red underlined text are toolbar title, the second layout are not constrained correctly – Mohammed Alaa Dec 29 '19 at 19:15
  • Thaks for your answer Mohammed. To be totally honest, I do not understand why in my example the constraines are not correctly used. In the Layout editor in Android Studio you see the that the imageButtons are constrained (I added an additional screenshot). Maybe the problem is that I use a Scroll View and then defining the constraints becomme different? – VanessaF Dec 30 '19 at 11:12
  • 1
    this attributes `tools:layout_editor_absoluteX="0dp"` `tools:layout_editor_absoluteY="73dp"` works to align views in layout editor only not in the real view so you see the difference because it's works only in layout-preview you so you shouldn't use it production – Mohammed Alaa Dec 30 '19 at 12:02

2 Answers2

1

for MainActivity the text are for title you can remove it by applying them without toolbar and set your custom toolbar or follow this question

for SelectionActivity try this layout

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".MainActivity">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_mainActivity"
        android:layout_width="match_parent"
        android:layout_height="53dp"
        android:background="#435cb53f"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:titleTextColor="@android:color/holo_green_light" />


    <TextView
        android:id="@+id/textView_ToolBar_CocktailSelectionActivity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="TestText"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="@+id/toolbar_mainActivity"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/toolbar_mainActivity"
        tools:text="Selection" />

    <android.support.constraint.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar_mainActivity">


        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="0dp"
            android:layout_height="128dp"
            android:background="#00000000"
            android:scaleType="fitCenter"
            app:layout_constraintHorizontal_weight="1"
            app:layout_constraintEnd_toStartOf="@id/imageButton1"
            app:layout_constraintHorizontal_chainStyle="spread"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/logo" />


        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="0dp"
            android:layout_height="128dp"
            android:background="#00000000"
            android:scaleType="fitCenter"
            app:layout_constraintHorizontal_weight="1"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@id/imageButton2"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/logo" />

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="0dp"
            android:layout_height="128dp"
            android:background="#00000000"
            android:scaleType="fitCenter"
            app:layout_constraintVertical_chainStyle="packed"
            app:layout_constraintEnd_toStartOf="@id/imageButton4"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/imageButton2"
            app:srcCompat="@drawable/logo" />

        <ImageButton
            android:id="@+id/imageButton4"
            android:layout_width="0dp"
            android:layout_height="128dp"
            android:background="#00000000"
            android:scaleType="fitCenter"
            app:layout_constraintStart_toEndOf="@id/imageButton3"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/imageButton2"
            app:srcCompat="@drawable/logo" />

        <ImageButton
            android:id="@+id/imageButton5"
            android:layout_width="0dp"
            android:layout_height="128dp"
            android:background="#00000000"
            android:scaleType="fitCenter"
            app:layout_constraintVertical_chainStyle="packed"
            app:layout_constraintEnd_toStartOf="@id/imageButton6"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/imageButton3"
            app:srcCompat="@drawable/logo" />

        <ImageButton
            android:id="@+id/imageButton6"
            android:layout_width="0dp"
            android:layout_height="128dp"
            android:background="#00000000"
            android:scaleType="fitCenter"
            app:layout_constraintStart_toEndOf="@id/imageButton3"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@id/imageButton3"
            app:srcCompat="@drawable/logo" />

    </android.support.constraint.ConstraintLayout>


</android.support.constraint.ConstraintLayout>

hope this help you in your issue, for more info in how to use constraintlayout check this codelab

Mohammed Alaa
  • 3,140
  • 2
  • 19
  • 21
  • Thanks Mohammed for your answer. Unfortnuately it does not wok. I only see white boxes without any pictures and if I move them the constraints are quite weird making the movement really difficulat. – VanessaF Dec 30 '19 at 11:09
  • Okay, now I have inserted the correct figures and for 4 imageButtons it works. But if I want to add an additional ImageButton things start to look weird. What did you actually change to construct the layout with the 4 buttons/areas? And how can I add burther areas into the Scroll View? – VanessaF Dec 30 '19 at 11:46
  • 1
    @Vanessaf have updated the answer by adding one more row , but I recommend to you to read about constraintlayout more you can follow the codelab I have mentioned before or check [link1](https://developer.android.com/training/constraint-layout),[link2](https://developer.android.com/reference/android/support/constraint/ConstraintLayout) – Mohammed Alaa Dec 30 '19 at 12:19
  • Thanks a lot Mohammed. I had a look into the tutorial. However, there they do not consider the problem of combining a ScrollView with a constrained Layout. If I do not use a Scroll View, the Constrained Layout looks how it looks in the XML layout file. I think that things become difficult, It I combine a Scroll View with a Constrained Layout – VanessaF Dec 30 '19 at 12:24
  • you are welcome @VanessaF `ScrollView` are just a container you can put any view inside it other than `ConstraintLayout` , and you use `ScrollView` if your views are to large to fit in screen so you make it scrollable – Mohammed Alaa Dec 30 '19 at 12:33
  • But in my example I use a Constrained Layout within a Scroll View, right? I once asked this question here: https://stackoverflow.com/questions/58306496/scrollview-with-constraint-layout. And they told me how to use a Scroll View with a Constrained Layout. I normally understand how a constrained layout works. The problem is - as said before - the combination of a Scroll View with a Constrained Layout. This is just difficult for me. Unfortnuately I could not find a good tutorial covering this problem. – VanessaF Dec 30 '19 at 12:43
  • Hi Mohammed, I read the tutorials, still I do not understand your constraints and I do not understand why my inital example is not correctly constrained. So in your example, you allign all buttons with the corresponding buttons on the other side (left and right horizontal constrainets). That is clear. But why do you sometimes allign buttoms diagonally (imageButton3) and sometimes just directly vertically (imageButton 5)? – VanessaF Dec 31 '19 at 11:38
  • you can try to apply what you have learned, and if you achieve this with a different way this is the goal, you don't have to be constrained only with my answer , of course you can achieve your goal in a lot of different ways – Mohammed Alaa Dec 31 '19 at 19:20
  • Is there a way how I can set the constraints in the Constrained Layout such that it looks like the layout in Layout-Editor? Why can I just not use the parents as constraints and thus I could just place the elements in the layout editor where I want them to be and there are displayed in the correct way – VanessaF Jan 01 '20 at 11:55
  • If you used the correct attributes it will look the same as Layout-Editor ,or if you need to used drag and drop you need to know how to use the Layout-Editor that's it – Mohammed Alaa Jan 01 '20 at 12:10
  • Hi it's me again. I still have very big problem combining the Scroll View with a Constrained Layout. Do you have any good tutorial for that. I have already spend a lot of time on that wihtout any success. I also tried many answers and suggestion from this forum (https://stackoverflow.com/questions/37349845/is-it-possible-to-put-a-constraintlayout-inside-a-scrollview) without success. This is why I would really appreciate some information about how to combined those two elements. – VanessaF Jan 19 '20 at 12:05
  • Hi @Vanessaf if your problem still exist you can edit your question,or if it's a new one just post another question, and I'm sure you will get a lot of help,also you can check [this](https://www.raywenderlich.com/9475-constraintlayout-tutorial-for-android-complex-layouts) for advanced using of Constrained-Layout – Mohammed Alaa Jan 19 '20 at 19:04
  • Thanks Mohammed for your reply. To be totally honest with you I have alreay posted two similar/related questions, but unfortunately people either do not want or can't help me, because they do not reply. Yes, the problem still exists. For me the biggest obstacle is to learn how to combine a ScrollView with Constrained Layout. Unfortunately in your posted tutorial this is also not covered. – VanessaF Jan 23 '20 at 20:32
  • So is it not really possible to combine the ScrollView with a Constrained Layout? – VanessaF Jan 26 '20 at 11:43
  • no it's possible of course, if you need any help we can arrange a chat – Mohammed Alaa Jan 26 '20 at 11:46
  • Thanks Mohammed for your answer. Would you advice me to use a constraint Layout in Combination with a ScrollView? I would like to have fixed toolbars at the top and at the bottom of the screen that are always visible. An the view itself should be scrollable. The content of the view should contain two columns with Image Buttoms. What is your opinion on that? – VanessaF Jan 26 '20 at 13:46
1

Here Selection Activity's xml file. Try this,

<ScrollView 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"
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <android.support.constraint.ConstraintLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent"


        tools:context=".MainActivity"
        tools:ignore="ExtraText">


        '<!--Learning: The following lines define a toolbar -->'

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_mainActivity"
            android:layout_width="match_parent"
            android:layout_height="53dp"
            android:background="#435cb53f"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:titleTextColor="@android:color/holo_green_light" />


        <TextView
            android:id="@+id/textView_ToolBar_CocktailSelectionActivity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="TestText"
            android:textColor="@android:color/white"
            android:textSize="24sp"
            android:visibility="visible"
            app:layout_constraintBottom_toBottomOf="@+id/toolbar_mainActivity"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.535"
            app:layout_constraintStart_toStartOf="@+id/toolbar_mainActivity"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.421"
            tools:text="Selection" />

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="1000dp"
            app:layout_constraintTop_toBottomOf="@+id/toolbar_mainActivity"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="73dp">


            <ImageButton
                android:id="@+id/imageButton"
                android:layout_width="210dp"
                android:layout_height="128dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.026"
                app:srcCompat="@mipmap/test_dish_2" />

            <ImageButton
                android:id="@+id/imageButton2"
                android:layout_width="210dp"
                android:layout_height="128dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.014"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.026"

                app:srcCompat="@mipmap/test_dish_1" />

            <ImageButton
                android:id="@+id/imageButton3"
                android:layout_width="210dp"
                android:layout_height="128dp"
                android:background="#00000000"
                android:scaleType="fitCenter"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.014"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/imageButton"
                app:srcCompat="@mipmap/cocktail_x" />

        </android.support.constraint.ConstraintLayout>


    </android.support.constraint.ConstraintLayout>
</ScrollView>
Ronak Ukani
  • 603
  • 5
  • 20
  • Thanks for your answer Ronak. For the main activity it works, but for the seleciton activity I get an error when I also insert the line "getSupportActionBar().setDisplayShowTitleEnabled(false)". I thin the problem is that in the selectionActivity I also use the same toolbar as in the mainActivity. However, if I want to change the toolbar in the selctionActivity from "android:id="@+id/toolbar_mainActivityActivity" to "android:id="@+id/toolbar_selectionActivityActivity" the toolbar in the selectionActivity is not displayed correctly anymore as the ImageButtons are displayed within the toolbar – VanessaF Dec 30 '19 at 12:10
  • Hi Ronak, any ideas why the toolbar in the selection Activity is not displayed correctly when I isert the code of the previous comment? – VanessaF Dec 31 '19 at 11:41
  • hello @VanessaF , is any theme apply in your selection Activity beside Tag of Selection Activity in Manifest File?? – Ronak Ukani Dec 31 '19 at 12:04
  • Hi Ronak, in the SelectionActivity XML file there is only a tag: "android:id="@+id/toolbar_mainActivity". There is no tag with a toolbar for selection. I wanted to create it by changing the tag into : "android:id="@+id/toolbar_selectionActivityActivity". But this leads to the toolbar beeing displayed in a wrong way. And I do not understand why. My aim is to crate a new toolbar for the SelectionActicity that has the same properties as the one for the MainActivity but just other names and other text. How can I do that. – VanessaF Dec 31 '19 at 13:57
  • i think your xml file is proper. can you share your Menifestfile? – Ronak Ukani Dec 31 '19 at 14:30
  • Hi Ronak, I just posted the Manifest file in the initial post. Hope it helps. Thanks for your effort. – VanessaF Dec 31 '19 at 14:39
  • Thanks for sharing manifest file. i just want to check you apply theme or not but here everything is fine. i check your selectionActivity's xml file. you apply wrong constraint . i edit my answer and post selectionactivity's xml file just copy and past to your code and tell me what happen? – Ronak Ukani Dec 31 '19 at 14:57
  • Thanks Ronak for your comment and effort. Regarding the positioning of the ImageButtom it works, altough I do not understand why in your example the constraints are correct and in my previous example the constraints are not correct. But regarding the titles of the Activities there are still errors in it. Two titels are displayed and both are wrong (not the one I specified in the layout editor). This is really strange – VanessaF Jan 01 '20 at 11:53
  • Any idea regarding the wrong titels? What I basically want is to have a similar toolbar for every activity but with adjusted names. Somehow this is not working in my example. The titels are displayed in a wrong way. – VanessaF Jan 02 '20 at 20:35