Hii guys here in small screen size i am facing issue in edittext it is not clearly visible but in large screen size it is showing goodThis is a large screen image with 6inchThis is the error once with 5inch screen
Here i post a snippet of code where there are no. of tables which i created using linear layout but in small screen sie its getting hide i have tried making the heigth to wrap content but still its not resolving
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimaryDark1"
app:title="Work Details"
app:titleTextColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shramanand Tapsil for the Month: "
android:textColor="#000"
android:textSize="16sp" />
<TextView
android:id="#+id/month121"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textColor="#000"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="100dp"
android:background="#drawable/ic_down"
android:orientation="vertical"
android:weightSum="8.8">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.2"
android:orientation="horizontal"
android:weightSum="4">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.6">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#android:color/black"
android:textSize="14dp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".8"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Quantity"
android:textColor="#android:color/black"
android:textSize="15sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".9"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Hour Multiplier"
android:textColor="#android:color/black"
android:textSize="15sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".7"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Shramanand Hours"
android:textColor="#android:color/black"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".7"
android:orientation="horizontal"
android:weightSum="4">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.6"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="All 1 Day Paid activities "
android:textColor="#android:color/black"
android:textSize="12sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".8"
android:gravity="center">
<EditText
android:id="#+id/edt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="__"
android:inputType="number"
android:maxLength="3"
android:paddingLeft="8dp"
android:textColor="#android:color/black"
android:textCursorDrawable="#null"
android:textSize="13sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".9"
android:gravity="center">
<TextView
android:id="#+id/txtHours1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x 6"
android:textColor="#android:color/black"
android:textSize="16sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black" />
<Button
android:id="#+id/btnSubmit"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="right|bottom"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="20dp"
android:background="#drawable/rounded_corner_button_bg"
android:text="Next"
android:textColor="#fff" />
</LinearLayout>
</ScrollView>
</LinearLayout>
You could try setting a wrap_content height on the horizontal LinearLayout of the first row, so that it fits the content, by replacing:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.2"
android:orientation="horizontal"
android:weightSum="4">
with
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">
It could be because you have hard-coded the text size and it is too large.
I recommend this library (https://github.com/intuit/sdp) for setting the size of the text. It will scale your text size based on screen size.
Related
I have created one layout in android. the issue I am facing is in some case there are two lines of description and in some cases there is only one line of description. and My layout height automatically adjust base on that. but I want to fix my layout height in every case. means my layout height should be equal in every case. Below is the XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_marginRight="3dp"
android:layout_marginLeft="3dp"
android:layout_marginBottom="3dp">
<androidx.cardview.widget.CardView
android:layout_height="wrap_content"
android:layout_width="300dp"
app:cardCornerRadius="4dp"
app:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/notificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:maxLines="1"
android:text="Title"
android:textSize="18sp"/>
<TextView
android:id="#+id/notificationDescription"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Description"
android:layout_marginBottom="4dp"
android:maxLines="2"
android:textSize="14sp"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="#f2f2f2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".3"
android:orientation="vertical">
<TextView
android:id="#+id/notificationDealPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:text="Deal Price"
android:textColor="#3691e9"
android:textSize="16sp" />
<TextView
android:id="#+id/notificationActualPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/notificationDealPrice"
android:text="Actual Price"
android:background="#drawable/strike_thru"
android:textColor="#757575"
android:textSize="16sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"
android:orientation="vertical">
<TextView
android:id="#+id/notificationDiscountPercentage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10% OFF"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="18dp"
android:textStyle="bold"
android:visibility="visible" />
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="#f2f2f2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="72"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Coupon Code" />
<TextView
android:id="#+id/notificationCouponCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:gravity="center"
android:singleLine="true"
android:text="Not Required"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#308fe9"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="#f2f2f2" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="72"
android:orientation="vertical">
<Button
android:id="#+id/notificationUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="GET DEAL"
android:background="#78ca28"
android:textColor="#fff"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Image attached for the better understanding of the problem.
enter image description here
You can add in the description TextView this attribute: android:minLines="2"
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!!
I'm designing a UI using android studio and my problem is that I see a free space on the design editor and the emulator but not on the device .
here is how it looks on the design editor and the emulator
enter image description here
and here is how it looks on the device
enter image description here
and here is the 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="com.example.MyPfe.ClientInterface">
<LinearLayout
android:id="#+id/global_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_above="#id/Butt_layout"
android:weightSum="2"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:weightSum="1"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="10dp"
android:src="#drawable/ic_car" />
<Button
android:layout_width="200dp"
android:layout_height="30dp"
android:textAlignment="center"
android:text="Document à transmettre"
android:textSize="12dp"
android:textColor="#color/backgroundcolor"
android:layout_marginTop="5dp"
android:background="#color/sogreen"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/textcolor"
android:text="CONTRAT AUTO N°"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="nome et prenom"
android:textColor="#color/textcolor"/>
</LinearLayout>
<View
android:layout_marginTop="10dp"
android:layout_width="250dp"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/textcolor"
android:text="Début du contrat le"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="Échéance le"
android:textColor="#color/textcolor"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="2"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:id="#+id/cons_cont_lin"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/cerclebackgroundgreen"
android:padding="10dp"
android:src="#drawable/ic_consulter_contrat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Consulter mon contrat"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/cerclebackgroundgreen"
android:padding="10dp"
android:src="#drawable/ic_consulter_contrat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Modifier mon contrat"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/cerclebackgroundgreen"
android:padding="10dp"
android:src="#drawable/ic_consulter_contrat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Suivre un sinistre"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/cerclebackgroundgreen"
android:padding="10dp"
android:src="#drawable/ic_consulter_contrat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Déclarer un sininstre"
android:textAlignment="center"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/Butt_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="#+id/bt_depannage"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/sogreen"
android:text="URGENCE ET DÉPANNAGE"
android:textAlignment="center"
android:textColor="#color/backgroundcolor"
android:textSize="15sp" />
</RelativeLayout>
</RelativeLayout>
There is no issue with your rendering. The device resolution in the emulator and designer view is higher than your real device. Try setting the designer or your emulator to the same width and height as your device and you will see its all the same.
From what I see, the lower part containing the icons is aligned to the baseline/bottom etc. of the parent container or something like that. I think your device is 4.5" or 5" screen while your designer and your emulator is a 6" screen.
This is my xml file
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="testFun:"
android:textColor="#color/text_black"
android:textSize="#dimen/titleTextSize"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/gray" />
<RelativeLayout
android:id="#+id/layout_currentStation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"></View>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:singleLine="true"
android:text="tv_station:"
android:textColor="#color/text_black"
android:textSize="20sp" />
<TextView
android:id="#+id/tv_currentStation"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="6"
android:background="#drawable/shape_home_white_r6"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#color/text_black"
android:textColorHint="#color/text_gray"
android:textSize="20sp" />
<ImageView
android:id="#+id/img_nomal_state_arrow"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/icon_arrow_down" />
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"></View>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/testLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="test" />
</LinearLayout>
</LinearLayout>
I think android system will allocate rest of the space to "testLayout", because it is the only one specify the "layout_weight" attribute, but the result is:
The "testLayout" is just disappear, why?
Change height of both View in Relative layout(use fix height in dp).
<RelativeLayout
android:id="#+id/layout_currentStation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="5dp" // fix it in dp
android:layout_weight="1"></View>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:singleLine="true"
android:text="tv_station:"
android:textColor="#color/text_black"
android:textSize="20sp" />
<TextView
android:id="#+id/tv_currentStation"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="6"
android:background="#drawable/shape_home_white_r6"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#color/text_black"
android:textColorHint="#color/text_gray"
android:textSize="20sp" />
<ImageView
android:id="#+id/img_nomal_state_arrow"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/icon_arrow_down" />
<View
android:layout_width="0dp"
android:layout_height="5dp" // fix it in dp
android:layout_weight="1"></View>
</LinearLayout>
</RelativeLayout>
hope it helps.
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="testFun:"
android:textColor="#color/text_black"
android:textSize="#dimen/titleTextSize"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/gray" />
<RelativeLayout
android:id="#+id/layout_currentStation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"></View>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:singleLine="true"
android:text="tv_station:"
android:textColor="#color/text_black"
android:textSize="20sp" />
<TextView
android:id="#+id/tv_currentStation"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="6"
android:background="#drawable/shape_home_white_r6"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#color/text_black"
android:textColorHint="#color/text_gray"
android:textSize="20sp" />
<ImageView
android:id="#+id/img_nomal_state_arrow"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/icon_arrow_down" />
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"></View>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/testLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="test" />
</LinearLayout>
There is no orientation in the testLayout, try to add a vertical or horizontal orientation to it
EDIT
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="testFun:"
android:textColor="#color/text_black"
android:textSize="#dimen/titleTextSize"
android:textStyle="bold" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/gray" />
<RelativeLayout
android:id="#+id/layout_currentStation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"></View>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:singleLine="true"
android:text="tv_station:"
android:textColor="#color/text_black"
android:textSize="20sp" />
<TextView
android:id="#+id/tv_currentStation"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="6"
android:background="#drawable/shape_home_white_r6"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="#color/text_black"
android:textColorHint="#color/text_gray"
android:textSize="20sp" />
<ImageView
android:id="#+id/img_nomal_state_arrow"
android:layout_width="30dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/icon_arrow_down" />
<View
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"></View>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/testLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="test" />
</LinearLayout>
I set the Views height to 40dp same as the TextView height and now "testLayout" is visible at the bottom
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>