I make my Android app. Client’s requirement is to put logo to the bottom toolbar. The problem is that logo should be placed half over the bottom toolbar and half over the content. The problem is that I can not to negative margins, so I cannot shift logo image neither down from content, nor up over the toolbar. It should look so:
I made two toolbars – transparent and filled. But the problem is that I cannot stretch bottom of the content to the top of the filled toolbar because it is inside the transparent toolbar. Here is the picture and code.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBrandColor"
app:popupTheme="#style/Theme.AppCompat.Light.DarkActionBar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<ImageView
android:id="#+id/imageViewTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:src="#drawable/sponge_bob" />
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/content_frame_to_inflate"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf ="#+id/toolbarTop"
app:layout_constraintBottom_toTopOf="#+id/toolbarBottomTransparent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarBottomTransparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/content_frame_to_inflate"
app:contentInsetStart="0dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" >
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarBottomFilled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBrandColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="32dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="64dp"
android:src="#drawable/sponge_bob_logo"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
</android.support.constraint.ConstraintLayout>
How can I do proper layout?
Try something like this.
<?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="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#cdcdcd"
app:popupTheme="#style/Theme.AppCompat.Light.DarkActionBar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<ImageView
android:id="#+id/imageViewTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp" />
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/content_frame_to_inflate"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf ="#+id/toolbarTop"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#cdcdcd"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</RelativeLayout>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#000000"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"/>
</RelativeLayout>
UPDATED LAYOUT
<?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="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbarTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4984ad"
app:popupTheme="#style/Theme.AppCompat.Light.DarkActionBar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/content_frame_to_inflate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbarTop"
android:layout_above="#+id/bottomBar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="#drawable/background"/>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#4984ad"
android:id="#+id/bottomBar"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</RelativeLayout>
<ImageView
android:layout_width="200dp"
android:layout_height="70dp"
android:src="#drawable/SpongeBob_SquarePants_logo"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"/>
</RelativeLayout>
Related
I have a question about my Android app. I have a fragment in which I want to scroll. Should I use the ScrollView in the fragment or in the main activity (the fragment is used for navigation in toolbar)?
Also, should I use ScrollView or RecyclerView? Here is what I tried so far, but it didn't work.
This is the main activity xml, where I added the ScrollView.
<?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:fillViewport="true"
android:isScrollContainer="false">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottomAppBar" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:backgroundTint="#color/green_700"
app:fabAlignmentMode="center"
app:fabCradleMargin="10dp"
app:fabCradleRoundedCornerRadius="30dp"
app:fabCradleVerticalOffset="10dp"
app:contentInsetStart="0dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:itemIconTint="#color/light_grey"
app:itemTextColor="#color/light_grey"
app:itemTextAppearanceActive="#font/josefin_sans_semibold"
android:background="#drawable/background_transparent"
app:menu="#menu/bottom_navigation_menu" />
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onPressFab"
android:src="#drawable/ic_add"
app:layout_anchor="#id/bottomAppBar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</ScrollView>
And this is the fragment where I need scrolling. It is the home fragment from toolbar.
<?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:fillViewport="true"
android:isScrollContainer="false">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/myCoordinatorLayout"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
app:layout_constraintTop_toTopOf="parent">
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.card.MaterialCardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="100dp"
app:cardBackgroundColor="#color/green_700"
app:cardElevation="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.428"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="#style/ShapeAppearanceOverlay.MaterialCardView.Cut">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/search_outline"
android:fontFamily="#font/josefin_sans_semibold"
android:hint="Search Barcode"
android:inputType="text"
android:maxLines="1"
android:paddingLeft="30dp"
android:paddingTop="10dp"
android:paddingRight="30dp"
android:paddingBottom="10dp"
android:textColor="#color/dark_grey"
android:textColorHint="#color/grey_200"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.183"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/sbutton"
android:layout_width="90dp"
android:layout_height="60dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="16dp"
android:background="#drawable/background_transparent"
android:drawableLeft="#drawable/search_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<ImageView
android:id="#+id/imageView4"
android:layout_width="450dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="64dp"
android:layout_marginRight="64dp"
android:src="#drawable/home_image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView3"
android:layout_width="208dp"
android:layout_height="138dp"
android:layout_marginTop="120dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="4dp"
android:gravity="center"
android:text="Welcome back!"
android:textColor="#color/darker_grey"
android:textSize="40sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/myCoordinatorLayout" />
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewPager"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_marginTop="340dp"
android:clipToPadding="false"
android:foregroundGravity="center"
android:overScrollMode="never"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.16"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/myCoordinatorLayout">
</androidx.viewpager.widget.ViewPager>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I would be grateful if you have any suggestions. Thank you!
RecyclerView is used to make lists.
Try put yout fragment code inside a ScrollView and remove it from your activity.
I am Working on the Layout to Design like First image I have tried to implement the Layout Like this I always get layout Like the Second Image i have added As I used this Library implementation 'de.hdodenhof:circleimageview:3.1.0' From this Link Link of Library
The Layout xml File I have used to Design the layout like this is
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:fitsSystemWindows="true">
<FrameLayout
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/cordinatorBottom"
app:layout_constraintTop_toTopOf="parent" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/cordinatorBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="32dp"
android:paddingBottom="0dp"
android:theme="#style/Theme.MaterialComponents.Light"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:fabAlignmentMode="center"
app:fabCradleMargin="10dp"
app:fabCradleRoundedCornerRadius="25dp"
app:fabCradleVerticalOffset="0dp"
android:background="#color/transparent"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="#drawable/background_transparent"
app:labelVisibilityMode="selected"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/menu_bottom" />
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/plussign"
app:layout_anchor="#id/bottom_bar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout></androidx.constraintlayout.widget.ConstraintLayout>
Here is My XML Where I have Created ImageView and having a text under it
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="18dp"
android:gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/img"
android:layout_width="#dimen/_67sdp"
android:layout_height="#dimen/_67sdp"
android:contentDescription="#string/app_name"
app:civ_border_color="#FF000000"
app:civ_border_width="#dimen/_2sdp" />
<TextView
android:id="#+id/txt"
android:textSize="8sp"
android:text="Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="normal"/>
I want to Design this layout and i am getting the Layout Like this after all of above Effort in Code
Now layout is looking like this
I have the following problem:
On my android program I can create imageViews and buttons via a click on a button. These new buttons and imageViews get created at the top left corner at the 0,0 coordinate. The problem is now that I included a toolbar now instead of the standard ActionBar. When my buttons and imageViews are created now, they overlapped by the toolbar. I need a possibility to either change the coordinate system beneath the toolbar or simply make the toolbar not overlappable.
I already tried working with different layouts, like including the toolbar in a Linear Layout, the main layout beneath it etc. but I found nothing that works!
I ask for help, thank you very much!
MainActivity.xml
<?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:id="#+id/root_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"/>
<Button
android:id="#+id/aaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:onClick="bbb"
android:text="#string/ccc"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/ddd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="eee"
android:text="#string/fff"
app:layout_constraintBottom_toTopOf="#+id/ggg"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/hhh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="iii"
android:text="#string/jjj"
app:layout_constraintBottom_toTopOf="#+id/kkk"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/lll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="mmm"
android:text="#string/ooo"
app:layout_constraintBottom_toTopOf="#+id/nnn"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/ppp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="validate"
android:text="#string/qqq"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/rrr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="sss"
android:text="#string/ttt"
app:layout_constraintBottom_toTopOf="#+id/uuu"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/vvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="www"
android:text="#string/button_share"
app:layout_constraintBottom_toTopOf="#+id/xxx"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
MainActivity.java
Here I also added the toolbar in replacement for the ActionBar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
Edit:
MainActivity.xml with the ?android attribute which handels the problem visually but doesn't solve the problem at all.
MainActivity.xml
<?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:id="#+id/root_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"/>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize">
<Button
android:id="#+id/aaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:onClick="bbb"
android:text="#string/ccc"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/ddd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="eee"
android:text="#string/fff"
app:layout_constraintBottom_toTopOf="#+id/ggg"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/hhh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="iii"
android:text="#string/jjj"
app:layout_constraintBottom_toTopOf="#+id/kkk"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/lll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="mmm"
android:text="#string/ooo"
app:layout_constraintBottom_toTopOf="#+id/nnn"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/ppp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="validate"
android:text="#string/qqq"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/rrr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="sss"
android:text="#string/ttt"
app:layout_constraintBottom_toTopOf="#+id/uuu"
app:layout_constraintEnd_toEndOf="parent" />
<Button
android:id="#+id/vvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="www"
android:text="#string/button_share"
app:layout_constraintBottom_toTopOf="#+id/xxx"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
Change the .xml of toolbar to this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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="your path to the activity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/your_xml_for_activity_the_one_with_buttons" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
And in MainActivity.java use:
setContentView(R.layout.toolbar);
Like this you will create the toolbar, and will use the content of the buttons xml to be displayed under it.
Here is an example that can get you on your way as I dont know what the layout is you are trying to accomplish but this layout stacks the buttons starting below the toolbar.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="#+id/root_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"/>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/aaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Button1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar"/>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/ddd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"
app:layout_constraintTop_toBottomOf="#+id/aaa"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/hhh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3"
app:layout_constraintTop_toBottomOf="#+id/ddd"
app:layout_constraintStart_toStartOf="parent" />
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/lll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4"
app:layout_constraintBottom_toTopOf="#+id/hhh"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/ppp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button5"
app:layout_constraintTop_toBottomOf="#+id/lll"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/rrr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button6"
app:layout_constraintTop_toBottomOf="#+id/ppp"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/vvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button7"
app:layout_constraintTop_toBottomOf="#+id/rrr"
app:layout_constraintStart_toStartOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
In my activity (ConstraintLayout) I have an actionbar and a container (for my viewpage adapater). In this container I am displaying various fragments.
My problem is that the fragments (also in ConstraintLayout) are not completely displayed, meaning they are cut off at the end. My assumption is that this happens because the fragment "doesnt know" about the action bar in the activity and thus thinks it has the full screen to use but instead this part which the action bar takes up is moved down and off from the screen. That's just an assumption maybe I am completely wrong. Anybody can help on how to make sure the fragment layout is somehow "fitted" right to the screen?
my activity xml with the actionbar:
<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="wrap_content"
tools:context=".TourActivity">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar"
tools:layout_editor_absoluteY="8dp"></include>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/app_bar" />
</android.support.constraint.ConstraintLayout>
the fragment xml:
<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=".TourActivity">
<TextView
android:id="#+id/test"
android:layout_width="388dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:gravity="center"
android:text="testtest testtest"
android:textSize="25dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.52"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/imageView"
android:layout_width="365dp"
android:layout_height="185dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/question"
tools:src="#android:color/darker_gray" />
<Button
android:id="#+id/answerButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="156dp"
android:layout_marginEnd="8dp"
android:text="answerButton1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView" />
<Button
android:id="#+id/answerButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:text="answerButton2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/answerButton1" />
<Button
android:id="#+id/answerButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:text="answerButton3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/answerButton2" />
</android.support.constraint.ConstraintLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/app_bar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
Pls give that a go.
Use Relative Layout in the main XML file
<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"
tools:context=".TourActivity">
<include
android:id="#+id/app_bar"
layout="#layout/app_bar"
tools:layout_editor_absoluteY="8dp"/>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/app_bar" />
</RelativeLayout>
I am facing this issue with coordinator layout about scrolling. For a specific position it wont scroll buy, After clicking on Add new button a list element gets added below. And if we scroll that item the coordinator layout behaves normally like expand and shrink. But when we try to scroll up by touching on the layout
main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cord"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:background="#4a90e2"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="#4a90e2"
app:statusBarScrim="#4a90e2"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="120dp"
android:paddingBottom="40dp"
android:layout_gravity="center|top"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Suzuki Swift !"
android:textStyle="bold"
android:textColor="#android:color/white"
android:textSize="30dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:gravity="center"
android:fontFamily="#font/latoregular"
android:text="Some Text to enter about swift."/>
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include
layout="#layout/test_one"/>
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/man"
android:layout_gravity="center|top"
android:layout_marginTop="8dp"
android:elevation="10dp"
app:layout_behavior="#string/simple_view_behavior"
app:behavior_dependsOn="#+id/app_bar"
app:behavior_dependType="y"
app:behavior_dependTarget="-176dp"
app:behavior_targetX="16dp"
app:behavior_targetY="8dp"
app:behavior_targetWidth="40dp"
app:behavior_targetHeight="40dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:text="Review For Swift"
android:textSize="18dp"
android:elevation="10dp"
android:layout_marginLeft="72dp"
android:layout_marginTop="-100dp"
android:gravity="center_vertical"
android:textColor="#android:color/white"
android:alpha="0"
app:layout_behavior="#string/simple_view_behavior"
app:behavior_dependsOn="#+id/app_bar"
app:behavior_dependType="y"
app:behavior_dependTarget="-206dp"
app:behavior_targetY="0dp"
app:behavior_targetAlpha="1"/>
</android.support.design.widget.CoordinatorLayout>
Included Layout in main.xml i.e. test_one.xml
<?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"
android:id="#+id/relative_layout"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff">
<android.support.v7.widget.CardView
android:id="#+id/cardOne"
app:cardUseCompatPadding="true"
app:cardElevation="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linear_layout"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/linearLoutTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/linearLoutOne"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ellipsize="end"
android:fontFamily="#font/latoregular"
android:maxLines="1"
android:text="Review For Swift add attributes below,"
android:textColor="#color/titleColor"
android:textSize="15sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="#drawable/white_border_round"
android:fontFamily="#font/latolight"
android:hint="Eg: Looks,Speed"
android:padding="4dp"
android:paddingEnd="8dp"
android:paddingStart="8dp"
android:textColorHint="#color/titleColor"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="#+id/add_row_button"
app:layout_constraintHorizontal_bias="0.096"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/userName" />
<Button
android:id="#+id/add_row_button"
android:layout_width="100dp"
android:layout_height="35dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:layout_weight="2"
android:background="#color/titleColor"
android:fontFamily="#font/latobold"
android:onClick="addRow"
android:text="Add"
android:textColor="#color/white"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<com.example.android.uidesigns.XmlClasses.InsertionListView
android:id="#+id/listview"
android:nestedScrollingEnabled="true"
android:layout_below="#id/cardOne"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
list_item.xml
<android.support.v7.widget.CardView
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_height="wrap_content"
android:layout_width="match_parent"
app:cardElevation="4dp"
app:cardCornerRadius="4dp"
app:cardUseCompatPadding="true">
<android.support.constraint.ConstraintLayout
android:id="#+id/item_linear_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal">
<!--<de.hdodenhof.circleimageview.CircleImageView-->
<!--android:id="#+id/image_view"-->
<!--android:layout_width="80dp"-->
<!--android:layout_height="80dp"-->
<!--android:layout_marginBottom="8dp"-->
<!--android:layout_marginStart="18dp"-->
<!--android:layout_marginTop="8dp"-->
<!--android:gravity="center_vertical"-->
<!--android:src="#drawable/man"-->
<!--app:layout_constraintBottom_toBottomOf="parent"-->
<!--app:layout_constraintStart_toStartOf="parent"-->
<!--app:layout_constraintTop_toTopOf="parent" />-->
<TextView
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:text="Hello"
android:textColor="#111"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>
I have added a Gif to make my problem clear. Please take a look.
----->[gif for understanding]: https://i.stack.imgur.com/uSGfX.gif
Finally, I found the solution.
Rather than including the layout, I wrote it in the same file within NestedScrollView.
Somehow it worked. Thanks for the help.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>