Not Able To align Footer at bottom of screen? - android

I am not able to align the footer at the Bottom of the screen.I have used RelativeLayout within which android:layout_alignParentBottom="true" but the layout is not displayed at the bottom of the screen.
loan_collection_layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/appbar_layout" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="#156B7A"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="125dp"
android:text="Branch Office : Dhankuta"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<View
android:layout_width="1dp"
android:layout_height="13dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="Tuesday -4 April,2017"
android:textColor="#FFFFFF"
android:textSize="10sp"
/>
</LinearLayout>
<!-- Loan collection -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Loan Collection"
android:textColor="#2493A7"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_gravity="center"
android:layout_marginLeft="120dp"
android:layout_marginRight="2dp"
android:src="#mipmap/filter" />
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_gravity="center"
android:text="Filter"
android:textSize="12sp"
android:textStyle="normal" />
<View
android:layout_width="1dp"
android:layout_height="15dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="#98A6A9" />
<ImageView
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_weight="0.01"
android:src="#mipmap/search" />
<TextView
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="Search"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
<!-- Linear Layout for 2nd Linear Layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<!-- 2nd liner layout ist column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="12dp"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:src="#mipmap/center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="Center:005"
android:textSize="10sp" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.03"
android:background="#FFFFFF" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/border"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="12dp"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:src="#mipmap/group" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="Group"
android:textSize="10sp" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.03"
android:background="#FFFFFF" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/border"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="12dp"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:src="#mipmap/loan_type" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="Loan Type"
android:textSize="10sp" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.03"
android:background="#FFFFFF" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/border"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="12dp"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:src="#mipmap/date" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="Date:"
android:textSize="10sp" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.03"
android:background="#FFFFFF" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/border"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="12dp"
android:layout_gravity="center"
android:layout_marginTop="7dp"
android:src="#mipmap/valuedate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="value date:"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout> <!-- Linear Layout 2nd ends Here -->
<!-- Linear Layout for Group code starts here-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<CheckBox
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:buttonTint="#000000" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Group Code"
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Member No."
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Member Name"
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Remain Price"
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Total"
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!-- 3rd layout starts here -->
<!-- After third layout you have yo add listView in here and listitem should be populated through the JSON Data -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<CheckBox
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:buttonTint="#333333"
android:checked="true" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#F3F3F3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="001"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#F3F3F3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text=" 001"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#F3F3F3">
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Bimala Rai"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#F3F3F3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="0.00"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#F3F3F3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="0.00"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout><!-- 3rd layout ends here-->
<!-- Linear Layout 4th starts here-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<CheckBox
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:buttonTint="#333333" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="001"
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="001"
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="Uranus"
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="0.00"
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/border_loan_collection">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="0.00"
android:textColor="#333333"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout> <!-- 4th linear layout ends here -->
<!-- Total Bottom Layout starts herel -->
<!-- Footer aligned to bottom -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_alignParentBottom="true"
android:text="Footer"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>
How can footer be displayed at bottom of screen??

You main view is LinearLayout which does not works the way you are trying it to.
For obtaining your desired result you need your main Layout to be Relative layout and then set align bottom true to your footer.
For eg:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- place all your view inside this layout-->
</LinearLayout>
<!--place your footer here with align bottom property set to true-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_alignParentBottom="true"
android:text="Footer"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout/>
This snippet should get you going.

You have two options, either follow #Anirudh Sharma's answer, or just make your RelativeLayout's height to match_parent.

Your parent linear layout will stack your views in the orientation you have provided in your layout in order, one after the other. android:layout_alignParentBottom="true" would work only for views defined inside a RelativeLayout and not in the way you have defined.
Make your parent layout as RelativeLayout instead of LinearLayout and it would work perfectly for you!

Add following just above your footer
<View
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp" />

The problem is AlignParentBottom only works when the view is inside a Relative Layout. Your Textview is inside a Linear Layout.Put it outside of the Linear Layout and Inside the parent Relative Layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/appbar_layout" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="#156B7A"
android:orientation="horizontal">
.
.
.
.
</LinearLayout>
<!-- Make sure your View is directly the child of Relative layout to use
alignParentBottom="true" -->
<!-- Footer aligned to bottom -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_alignParentBottom="true"
android:text="Footer"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>

try this:
<RelativeLayout
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#6AED83"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Footer"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>

Try below code, it will work
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
//Your other code will be here
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Footer"
android:layout_gravity="center"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>

Whatever you want in footer make sure you write code inside main parent layout(Relative layout) so u sill set android:layout_alignParentBottom="true"
and it will remain all the time
.Note that write that code just above the </RelativeLayout> (Closing of main parent layout ). So footer never get hidden by any other layout.

Related

Android : How to Create Dividers between Components

My goal is to obtain divider lines similar to the ones shown in the following picture:
Goal Picture Divider
I need to place a horizontal and vertical divider between LinearLayout
This is my User Interface XML Code:
<?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"
tools:context=".MainActivity"
android:background="#drawable/maingradiant">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="اطلاعات ورودی"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="فاکتور"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="هزینه ها"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تسویه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="سامانه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ارسال بار"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I am currently using RelativeLayout as the Root Element, and for each row, I am applying a horizontal LinearLayout followed by a vertical LinearLayout.
Based on my current layout, can I receive assistance on how to place the divider lines on my interface, much like the provided picture?
Thank you!
First of all, I would recomend you to use RecyclerView with GridLayoutManager for this purpose. creating recyclerview with gridmanager
but if you want stick with current design, you add line by creating a View in xml
For Vertical line
<View
android:layout_width="2dp" //thickness
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
For Horizontal line
<View
android:layout_width="match_parent"
android:layout_height="2dp"//thickness
android:background="#color/colorPrimary" />
for shading colors you should look for something like Gradient in android. How ro create Gradient in android
code looks like this.
<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:background="#drawable/maingradiant"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="اطلاعات ورودی"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="فاکتور"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="هزینه ها"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="تسویه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="سامانه"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:background="#color/colorPrimary" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/wheatallergyambericon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ارسال بار"
android:textColor="#android:color/black"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Happy coding!!

fixed width LinearLayout

I'm trying to get two linear layout side by side and put content inside of it.
I want the two linear layouts to be side by side, but the left one should take about 3/4 of the screen and the right one the rest of it.
This is my code: https://gitlab.com/snippets/1682040
But the two linear layouts always change the width and the height depending on the content.
How can I have two linear layouts side by side with fixed width and height?
A better solution with RelativeLayout is always welcome.
This is the result:
Use layout_weight property of LinearLayout and android:weightSum property for parent layout.
Do Something like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="15dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".75" // For First layout to 3/4
android:background="#color/colorPrimary"
android:gravity="left|center"
android:orientation="vertical">
//First Layout content Here
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25" // For Second layout to rest of screen
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical">
//Second Layout Content Here
</LinearLayout>
</LinearLayout>
I know that you asked for a solution with the LinearLayout but I suggest you to solve this problem with the ConstraintLayout. You will get incredible performance improvements without nested view.
In this sample I added a vertical guideline at 75% of from the left of the screen. I have only to remove the nested LinearLayouts and add the constraints to your views!
Try it out!
<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/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="628dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#color/colorPrimary"
android:gravity="left|center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/repository_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue"
android:textSize="20dp" />
<TextView
android:id="#+id/repository_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="AAAAA"
android:textColor="#color/gray"
android:textSize="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_fork_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_star_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="0dp"
android:layout_height="628dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/guideline4"
app:layout_constraintTop_toTopOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/user_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue" />
<TextView
android:id="#+id/first_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mock Name"
android:textColor="#color/lightGray" />
</LinearLayout>
<android.support.constraint.Guideline
android:id="#+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.75" />
Try this give Your first LinearLayout android:layout_weight=".75" so it can take 3/4 space in screen
than assign android:layout_weight="0.25" to Your second LinearLayout so it can take remaining space
<?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="horizontal"
android:padding="15dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75"
android:background="#color/colorPrimary"
android:orientation="vertical">
<TextView
android:id="#+id/repository_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/colorBlue"
android:textSize="20dp" />
<TextView
android:id="#+id/repository_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="AAAAA"
android:textColor="#color/colorGreen"
android:textSize="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_fork_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/colorPrimary"
android:textSize="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_star_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/colorPrimary"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/user_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/colorBlue" />
<TextView
android:id="#+id/first_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mock Name"
android:textColor="#color/colorRed" />
</LinearLayout>
</LinearLayout>
Seems like both of the weights are set to "1". Have you tried ".5"?
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorPrimary"
android:layout_weight="0.50"
android:gravity="left|center">
Try this I have added weight
<?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="horizontal"
android:padding="15dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".75"
android:background="#color/colorPrimary"
android:gravity="left|center"
android:orientation="vertical">
<TextView
android:id="#+id/repository_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue"
android:textSize="20dp" />
<TextView
android:id="#+id/repository_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="AAAAA"
android:textColor="#color/gray"
android:textSize="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_fork_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:src="#drawable/ic_menu_camera" />
<TextView
android:id="#+id/repository_star_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25"
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/user_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue" />
<TextView
android:id="#+id/first_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mock Name"
android:textColor="#color/lightGray" />
</LinearLayout>
</LinearLayout>
First remove weightSum attribute from parent layout.
If you want your first layout to be 3/4 of you should put weight 0.75 and 0.25 (1/4) for the other one like here:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorPrimary"
android:layout_weight=".75"
android:layout_gravity="left"
android:gravity="left|center">
<TextView
android:id="#+id/repository_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue"
android:textSize="20dp"/>
<TextView
android:id="#+id/repository_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:text="AAAAA"
android:textColor="#color/gray"
android:textSize="15dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera"/>
<TextView
android:id="#+id/repository_fork_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_camera"
android:layout_marginLeft="15dp"/>
<TextView
android:id="#+id/repository_star_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:textColor="#color/orange"
android:textSize="20dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorAccent"
android:layout_weight=".25"
android:gravity="center">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/user_image"
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AAAAA"
android:textColor="#color/blue"/>
<TextView
android:id="#+id/first_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mock Name"
android:textColor="#color/lightGray"/>
</LinearLayout>
try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".75"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#000"
android:textSize="16dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape_txt"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".25"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#000"
android:textSize="16dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape_txt"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
Change the weight sum to 4 in the parent layout and add weight as 3 for child linear layout so it can take 3/4 space and 1 to child linear layout so that it will take the remaining space.
<?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="horizontal"
android:padding="15dp"
android:weightSum="4">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#color/colorPrimary"
android:gravity="left|center"
android:orientation="vertical">
//Your contents
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorAccent"
android:gravity="center"
android:orientation="vertical">
//Your contents
</LinearLayout>
</LinearLayout>

Setting Image Exactly in Center

I have divided Screen in 4 horizontal and two vertical portion.I am using Linear Layout to display the ImageView and TextView.I am not able to set the imageView exactly in center of the Linear layout.
home_layout
<?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">
<include layout="#layout/appbar_layout" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#156C7F"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="125dp"
android:text="Branch Office : Dhankuta"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<View
android:layout_width="1dp"
android:layout_height="15dp"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:background="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:text="Tuesday - 4 April, 2017"
android:textColor="#FFFFFF"
android:textSize="10sp" />
</LinearLayout>
<!-- Main Linear Layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DFDFDF"
android:orientation="vertical">
<!-- first Frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- first row first column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:src="#mipmap/saving"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Saving Collection"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
<!-- first row second column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView **i have made changes here**
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:src="#mipmap/loancollection"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Loan Collection"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!-- 2nd frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- Second row first column -->
<LinearLayout **i have made changes here**
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:src="#mipmap/dailysaving"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Daily Saving"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
/>
</LinearLayout>
<!-- Second row Second column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="#mipmap/memberenrollment"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Member Enrollment"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!-- 3rd frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- Third row First column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="#mipmap/cashincashout"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Cash In-Out "
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
<!-- Third row Second column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="#mipmap/collectorledger"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Collector Ledger "
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!-- 4th frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- Fourth row First column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="#mipmap/summary"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Summary"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
<!-- Fourth row Second column -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="top|center"
android:layout_marginTop="10dp"
android:src="#mipmap/officesync"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Office Sync"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<!-- 4th frame end -->
</LinearLayout> <!-- main frame end Layout -->
</LinearLayout>
I have made changes on the first row first column and on the 1st row 2nd column
**I want the imageView to lie exactly in Center of the Linear Layout and then the Text will Adjust on the remaining portion.**How can this issue be solved?
UseBelowCode
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#156C7F"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="125dp"
android:text="Branch Office : Dhankuta"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<View
android:layout_width="1dp"
android:layout_height="15dp"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:background="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:text="Tuesday - 4 April, 2017"
android:textColor="#FFFFFF"
android:textSize="10sp" />
</LinearLayout>
<!-- Main Linear Layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DFDFDF"
android:orientation="vertical">
<!-- first Frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- first row first column -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/conference_room"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Saving Collection"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<!-- first row second column -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/conference_room"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Loan Collection"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
<!-- 2nd frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- Second row first column -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/conference_room"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Daily Saving"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<!-- Second row Second column -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/conference_room"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Member Enrollment"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
<!-- 3rd frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- Third row First column -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/conference_room"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Cash In-Out "
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<!-- Third row Second column -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/conference_room"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Collector Ledger "
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
<!-- 4th frame -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<!-- Fourth row First column -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/conference_room"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Summary"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<!-- Fourth row Second column -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/conference_room"
android:layout_centerInParent="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Office Sync"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
<!-- 4th frame end -->
</LinearLayout> <!-- main frame end Layout -->
LinearLayout Instead of RelativeLayout
<!-- first row first column -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="#ffffff"
android:orientation="vertical"
android:weightSum="2"
android:gravity="center">
<ImageView
android:id="#+id/sjkashjkasd"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/conference_room"
android:layout_weight="1.9"/>
<TextView
android:id="#+id/asdlkjl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Saving Collection"
android:textColor="#494949"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="0.1"/>
</LinearLayout>
If you want to use Linearlayout to match your requirement use below code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_border_help"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:gravity="center"
android:padding="15dp"
android:scaleType="fitCenter"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="HELLO"
android:textColor="#color/color_black" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_border_help"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:gravity="center"
android:padding="15dp"
android:scaleType="fitCenter"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="HELLO"
android:textColor="#color/color_black" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_border_help"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:gravity="center"
android:padding="15dp"
android:scaleType="fitCenter"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="HELLO"
android:textColor="#color/color_black" />
</LinearLayout>
</LinearLayout>
Output
You can set the gravity of the Linear Layout that is holding your views to centre, this way
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#156C7F"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="125dp"
android:text="Branch Office : Dhankuta"
android:textColor="#FFFFFF"
android:textSize="10sp" />
<View
android:layout_width="1dp"
android:layout_height="15dp"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:background="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:text="Tuesday - 4 April, 2017"
android:textColor="#FFFFFF"
android:textSize="10sp" />
</LinearLayout>
This simply means that any child elements inside of your linearLayout should be defaultly placed at the exact center of the layout. When you define the gravity for the linearlayout there will be no need to define elements layout_gravity, it will be automatically set to center.
add this line in LinearLayout
android:layout_width="match_parent"
android:gravity="center"

Android: Layout alignment

I have 3 'groups' of items in my layout:
Button + TextView (should be on the right side)
ImageView + ImageView + TextView (should be in center)
TextView + Button (should be on the left side)
It's like a footer for tablet.
But all my items are next to each other starting from left side.
I tried grouping them to separate layouts but it doesn't help.
Here is my code:
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="#android:color/black">
<Button
android:background="#drawable/arrow_left"
android:layout_width="50dp"
android:layout_height="match_parent"
android:id="#+id/footer_left_arrow"
android:layout_margin="10dp"/>
<TextView
android:text="text"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/footer_left_text"/>
<ImageView
android:background="#drawable/logo"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_width="50dp"
android:layout_height="20dp"
android:layout_gravity="center"/>
<ImageView
android:background="#drawable/footer_vertical_line"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<TextView
android:text="text"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center" />
<TextView
android:text="text"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<Button
android:background="#drawable/arrow_right"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_margin="10dp" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="bottom"
android:background="#android:color/black"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="#+id/footer_left_arrow"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/arrow_left" />
<TextView
android:id="#+id/footer_left_text"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="text"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/footer_vertical_line" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#android:drawable/ic_input_add" />
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="text"
android:textColor="#FFFFFF"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="text"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/arrow_right" />
</LinearLayout>
</LinearLayout>
Use this.

3 equal height rows in a ScrollView

Here is my layout XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/banner" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:id="#+id/row2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 1"
android:textColor="#color/darkBlue"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyRecipes"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAll1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_below="#id/row2" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:id="#+id/row3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 2"
android:textColor="#color/darkBlue"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyFavorites"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAllFavorites"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:layout_below="#id/row3" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
As you can see from my layout, the outer LinearLayout contains 3 RelativeLayout which all have layout_weight equals to 1 and the LinearLayout has weightSum equal to 3.
However, the behavior of the current layout is: The 1st RelativeLayout shared very little space (around 10%) and the 2nd & 3rd RelativeLayout shared 45% of height.
How can I make them equally shared the height?
Add to below attributes to ScrollView
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
Check layout below
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:fadingEdge="none"
android:fillViewport="true"
android:isScrollContainer="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#mipmap/banner" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="#+id/row2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 1"
android:textColor="#color/blue_360"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyRecipes"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAll1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row2"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="#+id/row3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu 2"
android:textColor="#color/blue_360"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvCountMyFavorites"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="10dp"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="12sp" />
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btnViewAllFavorites"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:text="View All"
android:textColor="#color/blue_360"
android:textSize="16sp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/group2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/row3"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Because your using scrollview you need to fill your view port to make the scroll view occupy the whole screen
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"/>
//..... your other code here
</ScrollView>

Categories

Resources