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"
Related
I have the following view:
And every time I edit the search EditText (even when there is no text change, just focusing), my View does this:
My XML code is this:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:windowSoftInputMode="adjustNothing"
tools:context="garbi.mx.garbi.Home">
<!-- The main content view -->
<RelativeLayout
android:id="#+id/mainContent"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent" >
<FrameLayout
android:layout_marginTop="80dp"
android:layout_marginBottom="140dp"
android:id="#+id/mapFrame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/map"
android:layout_marginTop="10dp"
android:layout_margin="10dp"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/geolocation"
android:layout_marginRight="20dp"
android:onClick="centerMap"
android:layout_marginBottom="30dp"
android:background="#00ffffff"
android:layout_gravity="bottom|right"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/marker"
android:layout_gravity="center" />
</FrameLayout>
<TextView
android:layout_marginTop="15dp"
android:layout_width="match_parent"
android:text="¿Dónde se encuentra tu coche?"
android:textColor="#43B9BD"
android:textStyle="bold"
android:gravity="center"
android:layout_height="25dp"
android:id="#+id/textView" />
<!--<EditText
android:id="#+id/places_autocomplete"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp"
android:textSize="14dp"
android:layout_height="55dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/imageView" />-->
<com.seatgeek.placesautocomplete.PlacesAutocompleteTextView
android:id="#+id/places_autocomplete"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp"
android:textSize="14dp"
android:layout_height="55dp"
app:pacv_googleMapsApiKey="AIzaSyBjn1_8gclbpsRvfO6ndKQKEuCLUaARw5s"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/imageView" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/search"
android:layout_below="#+id/textView"
android:layout_alignParentStart="true"
android:layout_marginStart="16dp"
android:id="#+id/imageView"
android:layout_alignBottom="#+id/places_autocomplete" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_above="#+id/imageButton">
<Button
android:layout_margin="5dp"
android:layout_width="0dp"
android:padding="5dp"
android:layout_height="50dp"
android:background="#drawable/field_small"
android:textAllCaps="false"
android:textColor="#color/textColor"
android:onClick="setCar"
android:id="#+id/carButton"
android:text="Agregar \nVehículo"
android:layout_weight="1"/>
<Button
android:layout_margin="5dp"
android:layout_width="0dp"
android:layout_height="50dp"
android:background="#drawable/field_small"
android:textAllCaps="false"
android:onClick="setPayment"
android:id="#+id/paymentButton"
android:textColor="#color/textColor"
android:text="Agregar \nMétodo de pago"
android:layout_weight="1"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Solicitar Garbi"
android:textSize="16dp"
android:textAllCaps="false"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textColor="#ffffff"
android:background="#drawable/large_button"
android:id="#+id/imageButton"
android:onClick="request"
android:layout_marginBottom="15dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<!-- The navigation drawer -->
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:id="#+id/drawerPane"
android:layout_gravity="start">
<!-- Profile Box -->
<RelativeLayout
android:id="#+id/profileBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#color/colorAccent"
android:onClick="editProfile"
android:padding="8dp" >
<ImageView
android:id="#+id/avatar"
android:layout_width="75dp"
android:layout_height="75dp"
android:src="#drawable/rain"
android:layout_marginTop="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/avatar"
android:orientation="vertical" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="15dp" />
<TextView
android:layout_marginTop="-10dp"
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Isabel Tapia Reyes"
android:textColor="#fff"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<!-- List of Actions (pages) -->
<ListView
android:layout_marginTop="100dp"
android:id="#+id/navList"
android:layout_width="280dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#null"
android:dividerHeight="0dp"
android:background="#ffffffff"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Experimenting with it has lead me to think this has to do with the length of the texts inside the buttons (they are dynamic). If the button has more than one line, it is going to get pushed down. One line does ok.
You can follow any of the two options:
1.Add android:baselineAligned="false" to your LinearLayout containing the buttons
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_above="#+id/imageButton"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="2">
2.Use android:layout_height="match_parent" for the child element to grow it's view equally when the text changes
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/imageButton"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/carButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:onClick="setCar"
android:padding="5dp"
android:text="Agregar \nVehículTestTestTestTestTest"
android:textAllCaps="false"
android:textColor="#color/color_black" />
<Button
android:id="#+id/paymentButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
android:onClick="setPayment"
android:text="Agregar \nMétodo de pago"
android:textAllCaps="false"
android:textColor="#color/color_black" />
</LinearLayout>
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.
I have my views in a scroll view so that if the content is bigger than the screen size, the user can scroll down. I have noticed a weird thing.
The first time the content comes up, it doesn't scroll. However, when the user changes a setting and the content of the views which are inside the scroll view reloads it does become scrollable.
Why is this? Is it clear what I mean?
EDIT: This only happens on my Nexus 5X. But when I used a Samsung J10 it works right away.
My XML is a relative layout, with a child element of the scroll view, which contains other views.
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.apps.reuven.egertandcohentravel.Activities.HomeActivity"
tools:showIn="#layout/activity_home">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="50dp"
android:id="#+id/progressBar"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:visibility="gone"
/>
<TextView
android:id="#+id/textViewLinkToOrder"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here to book travel insurance."
android:textColor="#color/colorPrimary"
android:layout_centerHorizontal="true"
android:textSize="24sp"
android:gravity="center"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/buttons_linear_layout"
android:orientation="horizontal"
android:layout_below="#id/textViewLinkToOrder">
<Button
android:layout_width="200dp"
android:id="#+id/choose_country_button"
android:onClick="onChooseCountryButtonClick"
android:layout_height="wrap_content"
android:text="Choose country"
android:layout_marginLeft="5dp"
android:background="#color/colorPrimary"
android:layout_weight="1"
android:textColor="#ffff"
android:layout_marginRight="5dp"
android:layout_below="#id/textViewLinkToOrder"
android:layout_centerHorizontal="true"/>
<Button
android:layout_width="200dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:textColor="#fff"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="#+id/automatic_country_button"
android:layout_height="wrap_content"
android:text="My Location"
android:layout_below="#id/choose_country_button"
android:layout_centerHorizontal="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayoutAllDetails"
android:layout_below="#id/buttons_linear_layout"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="No country yet selected"
android:gravity="center"
android:id="#+id/textView_coumtry_name"
android:textColor="#000000"
android:textSize="30sp"
android:padding="5dp"
android:textStyle="bold"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/police"/>
<TextView
android:textSize="17sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Police"
android:textColor="#000000"
android:layout_gravity="center_vertical" />
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/police_text_view"
android:text=""
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:id="#+id/police_phone_button"
android:layout_width="30dp"
android:layout_gravity="center_vertical"
android:layout_height="30dp"
android:src="#android:drawable/sym_action_call"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ambulance"/>
<TextView
android:textSize="17sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ambulance"
android:textColor="#000000"
android:layout_gravity="center_vertical" />
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ambulance_text_view"
android:text=""
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:layout_width="30dp"
android:layout_gravity="center_vertical"
android:layout_height="30dp"
android:src="#android:drawable/sym_action_call"
android:id="#+id/ambulance_phone_button"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/israel_consulate"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:textSize="17sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Israel Consulate"
android:textColor="#000000"
android:layout_gravity="center_vertical" />
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/israel_consulate_text_view"
android:text=""
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:layout_width="30dp"
android:layout_gravity="center_vertical"
android:layout_height="30dp"
android:src="#android:drawable/sym_action_call"
android:id="#+id/israel_phone_button"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/chabad"/>
<LinearLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:textSize="17sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beit Chabad"
android:textColor="#000000"
android:layout_gravity="center_vertical" />
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/chabad_address_text_view"
android:text="3 Blue Street, USA"
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/chabad_number_text_view"
android:text="+44 456 3245234"
android:textColor="#000000"
android:layout_gravity="center_vertical"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:layout_width="30dp"
android:layout_gravity="center_vertical"
android:layout_height="30dp"
android:src="#android:drawable/sym_action_call"
android:id="#+id/chabad_phone_button"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Thanks very much, I can't figure this one out.
I also had the same problem and by adding a TableLayout inside ScrollView solved the problem for me. Then, add your content (RelativeLayout) inside TableLayout.
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<-- Your RelativeLayout goes here -->
</TableLayout>
</ScrollView>
Let me know if that solved the problem. Do not forget to add the attribute fillViewport=true to ScrollView so the TableLayout match it's parent's view width and height.
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.
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>