How to use weightSum in RelativeLayout - java

I just Created a Relative Layout with id rl1 What I need I want to create a weightSum with 2 for this relative layout as to put in this layout another 2 relative layout one with id fireID and the other relative layout cartID which each of them take a weight 1 how can I silve this issue
this is my xml file
<LinearLayout 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:orientation="vertical"
tools:context="abtech.waiteriano.com.waitrer.MenuActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" />
<!-- <FrameLayout
android:id="#+id/content_frame"
android:layout_width="matc
h_parent"
android:layout_height="wrap_content"></FrameLayout>-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:id="#+id/rl1"
android:orientation="horizontal"
android:weightSum="2">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/fireID">
</FrameLayout>
<RelativeLayout
android:id="#+id/fireID"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#ff6b6b"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:src="#drawable/fire" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/cartID"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#ff6b6b"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<ImageView
android:id="#+id/imageCart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:src="#drawable/shoppingcart" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>

We can't use Weight in RelativeLayout.

Related

Change Constraintlayout to LinearLayout

:)
I want to change my constraintlayout to a LinearLayout. I tried it with the green (second area) and it worked perfectly. Unfortunately, the top part doesn't work as well as the bottom part. The problem is that the red area always occupies the entire area and does not go to the toolbar.
How can I make the height of the red area only up to the toolbar + distance?
I don't want to change something "more" in my Toolbar XML, otherwise the layout on all other pages is wrong.
Is there an option that allows android: layout_height = "match_parent- toolbar"?
I would like it to end up looking like the second picture. The red area should be at a distance from the toolbar and be at a maximum. So no matter how much content is in the red area, it should always be as large as possible by far. How can I do that? I'm really looking forward to helpful answers! Thanks in advance.
My current status:
What I want to achieve:
My try
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="#ececec"
android:orientation="horizontal">
<androidx.cardview.widget.CardView
android:id="#+id/cardViewMiddle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:elevation="8dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:gravity="center"
app:cardBackgroundColor="#color/Red"
app:cardCornerRadius="15dp">
</androidx.cardview.widget.CardView>
</LinearLayout>
XML
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ececec">
<androidx.cardview.widget.CardView
android:id="#+id/cardViewMiddle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:elevation="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:gravity="center"
app:cardBackgroundColor="#color/Red"
app:cardCornerRadius="15dp"
app:layout_constraintBottom_toTopOf="#+id/cardViewCheckout"
app:layout_constraintTop_toTopOf="parent">
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardViewCheckout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="10dp"
android:elevation="8dp"
app:cardBackgroundColor="#fff"
app:cardCornerRadius="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:layout_gravity="center">
<TextView
android:id="#+id/textViewSumme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Summe "
android:layout_gravity="center"/>
<TextView
android:id="#+id/textViewSumme2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0,00"
android:layout_gravity="center"/>
</LinearLayout>
<Button
android:id="#+id/btn_user_geldaufladen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/button_order_checkout"
android:backgroundTint="#04C3B1"
android:elevation="16dp"
android:text="AUFLADEN"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_marginBottom="10sp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Toolbar
<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=".UserHomeActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/user_content_main"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Try 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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ececec"
android:padding="16dp"
android:orientation="vertical"
android:layout_below="#+id/appBar"
android:weightSum="10">
<androidx.cardview.widget.CardView
android:id="#+id/cardViewMiddle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:elevation="8dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:gravity="center"
app:cardBackgroundColor="#f00"
app:cardCornerRadius="15dp"
app:layout_constraintBottom_toTopOf="#+id/cardViewCheckout"
app:layout_constraintTop_toTopOf="parent">
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/cardViewCheckout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="10dp"
android:elevation="8dp"
app:cardBackgroundColor="#fff"
app:cardCornerRadius="15dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:layout_gravity="center">
<TextView
android:id="#+id/textViewSumme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Summe "
android:layout_gravity="center"/>
<TextView
android:id="#+id/textViewSumme2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0,00"
android:layout_gravity="center"/>
</LinearLayout>
<Button
android:id="#+id/btn_user_geldaufladen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/colorPrimaryDark"
android:backgroundTint="#04C3B1"
android:elevation="16dp"
android:text="AUFLADEN"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:layout_marginBottom="10sp"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/appBar"
>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="?attr/colorPrimary"
/>
</com.google.android.material.appbar.AppBarLayout>
</RelativeLayout>
Could you try to replace your (include) tag with this:
<include layout="#layout/user_content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
/>

Bottom Navigation View goes up with windowSoftInputMode=adjustResize

I need windowSoftInputMode= adjustRezise for my layout so that my buttons go up with the keyboard. BUT I don't want my BottomNagivationView to be affected by this.
How can I solve such?
My BottomNavigationView comes from MainActivity.xml which is:
<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"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_navigation"></FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
app:menu="#menu/bottom_menu"/>
</RelativeLayout>
My manifest has android:windowSoftInputMode="adjustPan" but I adjust it by code when I open the fragment with:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Here are some pictures so you could understand what I mean: https://imgur.com/a/vjePxI6
So what I would like to know is how I could set the BottomNavigationView to do nothing on keyboard opening while I'd like my buttons to be affected by :
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
In my case problem solved by just adding following line in manifest file.
android:windowSoftInputMode="adjustResize|adjustPan"
add android:windowSoftInputMode="adjustPan" inside your activity tag into your manifest file.
then go to your activity and change the parent layout to RelativeLayout, then create your FrameLayout which holds your fragments inside your relative layout which is your parent layout. Then add your second layout which is LinearLayout that holds the bottomNavigationView and make its Height and width match_parent but below the FrameLayout.
Below is the example of the main activity 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:orientation="vertical"
tools:context=".MainActivity">
//FrameLayout which holds all your fragments
<FrameLayout
android:id="#+id/fragments_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
//BottomNavigationView Container
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="bottom"
android:layout_below="#id/fragments_container">
//BottomMenus
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/bottom_navigation"
android:background="#drawable/rectangle_4_dash"
android:layout_alignParentBottom="true">
//Container of Menus
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="5">
//BottomMenu One
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="#drawable/home_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Home" />
</LinearLayout>
//BottomMenu Two
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="#drawable/contact_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Contact" />
</LinearLayout>
//BottomMenu Three
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="#drawable/about_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="About"
android:layout_gravity="center"/>
</LinearLayout>
//BottomMenu Four
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<ImageView
android:layout_width="20dp"
android:layout_height="17dp"
android:layout_gravity="center"
android:src="#drawable/services_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Services"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
</com.google.android.material.bottomnavigation.BottomNavigationView>
</LinearLayout>
Then go to your fragment which you want to scroll and design it like below one.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Title Of Your Form"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/f_name"
android:inputType="textPersonName"
android:padding="10dp"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="#string/m_name"
android:inputType="textPersonName"
android:padding="10dp"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="#string/l_name"
android:inputType="textPersonName"
android:padding="10dp"
android:textSize="14sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:hint="Message"
android:inputType="text"
android:padding="10dp"
android:textSize="14sp" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="Send Messagge"
android:textAllCaps="false"
android:textColor="#color/white"
android:layout_marginBottom="40dp"/>
</LinearLayout>
</ScrollView>
That is how i solved it,
if you have any doubt please let me know but if its helps or looks like a correct answer please mark it as a correct answer thanks.

Change size layout ImageView when WebView scrolls

I have a project with Android Studio and in Activity I have content html using WebView. The Image should be shown as an ImageView to make it look good. I want to change the height of the ImageView when I scroll the WebView to the bottom and then back to normal size when I scroll back to the top. How can enable it?
Here is my xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:background="#ffffff"
android:orientation="vertical"
tools:context="com.demowordpress.app.DetailActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="220dp">
<ImageView
android:id="#+id/imageView"
android:scaleType="center"
android:layout_width="match_parent"
android:layout_height="220dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<TextView
android:padding="10dp"
android:id="#+id/textView"
style="#style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:ellipsize="end"
android:maxEms="10"
android:maxLines="3"
android:background="#android:drawable/screen_background_dark_transparent"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
</LinearLayout>
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/wv"
android:scrollbars="none"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:visibility="gone">
</WebView>
<ProgressBar
android:id="#+id/pBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
<Button
android:id="#+id/Button"
android:layout_width="80dp"
android:layout_height="80dp"
android:focusable="true"
android:clickable="true"
android:visibility="gone"
android:drawableTop="#drawable/ic_retry"
android:text="try Again"
android:textColor="#color/colorPrimary"
android:background="#android:color/transparent"
android:layout_gravity="center"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/white"
android:clickable="true"
ads:srcCompat="#drawable/ic_share"
app:backgroundTint="#color/white"
android:layout_gravity="end|bottom"
android:layout_marginBottom="50dp"
android:layout_marginRight="40dp"
/>
</FrameLayout>
</LinearLayout>

NestedScrollView not showing inside CoordinatorLayout

I have CoordinatorLayout with NestedScrollView and CollapsingToolbarLayout. I put everything inside CollapsingToolbarLayout which i want to show on screen first then add NestedScrollView to show more content but NestedScrollView is not visible on screen.
Here is my XML Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
android:clipToPadding="false"
android:background="?android:attr/colorBackground"
android:id="#+id/viewuserProfileMain"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/relativeParent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/upCoverPhoto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/redName"/>
<!--PUT TOOLBAR HERE-->
<RelativeLayout
android:id="#+id/upDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/diagonal_cut_layerlist"
android:elevation="12dp"
android:translationZ="12dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="115dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="115dp"
android:layout_marginRight="10dp"
android:gravity="end"
android:orientation="horizontal">
<Button
android:id="#+id/Button_FollowFriends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/AppButton"
android:text="Follow"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profilePicture_Cut"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/baby"
app:civ_border_width="2dp"
app:civ_border_color="#color/primary"
android:layout_marginTop="85dp"
android:layout_marginLeft="15dp"/>
<TextView
android:id="#+id/upUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/secondary_text"
android:layout_marginTop="10dp"
android:textSize="28sp"
android:layout_marginLeft="10dp"
android:text="Susan Ledger"/>
<TextView
android:id="#+id/upUserCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/home"
android:drawablePadding="5dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:textSize="18sp"
android:textColor="#color/secondary_text"
android:text="Delhi,India"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="#+id/Button_AddFriend"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="#style/AppButton"
android:text="Add Friend"
android:layout_weight="1"/>
<Button
android:id="#+id/Button_RejectRequest"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="#style/AppButton"
android:text="Reject"
android:layout_weight="1"/>
<Button
android:id="#+id/Button_MessageFriend"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="#style/AppButton"
android:text="Message"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/up_NestedScrollView"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
>
<!--To show tab on top of view pager-->
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabTextColor="#color/place_autocomplete_prediction_primary_text_highlight"
app:tabSelectedTextColor="#color/primary_text"
app:tabIndicatorColor="#color/primary_light"
android:id="#+id/up_Viewpager_Tab">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/userProfile_Viewpager_Tab"
android:id="#+id/up_Viewpager_ViewPager">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
try give
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true">
Because AppBar could not be match_parent
Give wrap_content in height of your AppBarLayout
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
And
`android:fitsSystemWindows="false"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"`
these lines to your CollapsingToolbarLayout

Android : Layout background inside toolbar

I want to create like bellow image.
For creating like this I write the bellow code.
<LinearLayout
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="posoft.shariful.rupkotharpata.Profile"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="220dp">
<include layout="#layout/toolbar"></include>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="#drawable/b1"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:contentDescription="#string/todo"
android:src="#drawable/p1"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginStart="20dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_marginStart="10dp"
android:layout_marginBottom="20dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingStart="10dp"
android:paddingEnd="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="#string/test_user_full_name"
android:textColor="#color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="19sp"
android:text="#string/test_user"
android:textColor="#color/white"
android:layout_marginTop="5dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
It working. But the problem is, It don't show app toolbar.
Note : The tools of toolbar working.
Now how I can show toolbar or toolbar tools?
This is happening because your LinearLayout is displaying over your toolbar(Views inside a RelativeLayout display over one other, and you haven't mentioned any view to display above or below the other one).
Assign an id to your toolbar, and instruct your LinearLayout to be below it, something like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="220dp">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"></include>
<LinearLayout
android:layout_below="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="#drawable/b1"
android:orientation="horizontal">
You might also need to increase your parent RelativeLayout's height from 220dp to something like 250dp to accommodate both the children without clipping the bottom one.
You need to use CollapsingToolbarLayout with AppBarLayout over there.
For your reference I have posted one xml file. refer this..
<android.support.design.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"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.news.moneycontrol.MainActivity">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bg_dashboard"
/>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="240dp"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="#dimen/toolbar_elevation"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!-- <ImageView
android:id="#+id/flexible_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#mipmap/home_cover"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"/>-->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/transparent"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<com.news.moneycontrol.progressbar.CircularProgressView
android:id="#+id/progress_view"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:padding="0dp"
android:layout_marginTop="100dp"
app:cpv_animAutostart="false"
app:cpv_indeterminate="true"
app:cpv_thickness="4dp" />
<ImageView
android:id="#+id/no_internet"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="150dp"
android:visibility="invisible"
android:src="#mipmap/ic_connection_error" />
<com.xxx.CustomFont
android:id="#+id/text_internet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#9B9B9B"
android:layout_gravity="center"
android:text="No Internet Connection"
android:textStyle="bold"
android:visibility="invisible"
android:layout_marginTop="270dp"
android:paddingBottom="10dp"/>
</android.support.design.widget.CoordinatorLayout>
hope you have listed below necessary gradles!
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
Add new scroll activity then in activity layout file put imageview in collapsing toolbar layout
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/test_background_image"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/groupImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY" />
</android.support.design.widget.CollapsingToolbarLayout>
Wrap the layout in toolbar as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="220dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="#color/colorPrimaryDark"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:contentDescription="todo"
android:src="#color/colorPrimaryDark"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_marginBottom="20dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingStart="10dp"
android:paddingEnd="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="Full name"
android:textColor="#color/colorAccent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="19sp"
android:text="user"
android:textColor="#color/theme_color"
android:layout_marginTop="5dp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</LinearLayout>

Categories

Resources