I have 4 LinearLayout with a layout_weight of 0.25 (each one of them uses 25% of the screen height), the first 3 LinearLayout contains an ImageView and a RelativeLayout with a layout_weight of 0.5 (they both take 50% of the LinearLayout width) and they work fine, the problem occurs on the last LinearLayout which contains 2 RelativeLayout, this is the structure:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/white">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/icon_news"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/newsTextView"
/>
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="News"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textColor="#color/mainBlue"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/white">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/icon_contacts"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/contactTextView"
/>
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contatti"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textColor="#color/mainBlue"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
This LinearLayout doesn't work, it doesn't take the 25% height of the screen and it's just not visible.. Is it a problem with RelativeLayout with layout_weight? what should I do to fix this?
EDIT
This is the whole XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:pew="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<ImageView
android:layout_height="wrap_content"
android:layout_weight=".5"
android:layout_width="0dip"
android:src="#drawable/img"
android:scaleType="centerCrop"/>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/mainBlue">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sezione 1"
android:gravity="left"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/mainBlue">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sezione 2"
android:gravity="left"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
<ImageView
android:layout_height="wrap_content"
android:layout_weight=".5"
android:layout_width="0dip"
android:src="#drawable/img"
android:scaleType="centerCrop"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<ImageView
android:layout_height="wrap_content"
android:layout_weight=".5"
android:layout_width="0dip"
android:src="#drawable/img"
android:scaleType="centerCrop"/>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/mainBlue">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sezione 1"
android:gravity="left"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/white">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/icon_news"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/newsTextView"
/>
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="News"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textColor="#color/mainBlue"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/white">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/icon_contacts"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/contactTextView"
/>
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contatti"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textColor="#color/mainBlue"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Add Linear Layout as Root Layout with weightSum 1.
Refer this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pew="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="horizontal"
android:weightSum="1.0">
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#mipmap/ic_launcher" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 1"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="horizontal"
android:weightSum="1.0">
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 2"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="horizontal"
android:weightSum="1.0">
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#mipmap/ic_launcher" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 1"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="horizontal"
android:weightSum="1.0">
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_above="#+id/newsTextView"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="News"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_above="#+id/contactTextView"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Contatti"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
hey I tested your code is it seems there is problem in hight you gave to each 4 child layout.
just replace
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
with
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
and do same for all 4 child views.
For reference
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:pew="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#drawable/cat1" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#android:color/holo_blue_bright" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 1"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#android:color/holo_blue_bright" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 2"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#drawable/cat2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#drawable/cat3" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#android:color/holo_blue_bright" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 1"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#fff" >
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_above="#+id/newsTextView"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#drawable/icon" />
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="News"
android:textColor="#android:color/holo_blue_bright"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#fff" >
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_above="#+id/contactTextView"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#drawable/icon" />
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Contatti"
android:textColor="#android:color/holo_blue_bright"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Happy coding.
Use below code to solve this issue:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/newsTextView"
/>
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="News"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/contactTextView"
/>
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contatti"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
I have tested my application in genymotion emulator using two Android OSs. Lollipop and Ice Cream Sandwich. Worked fine in both devices. Problem is when I tested in real devices, item positions and sizes get changed.
In my xiomi mi4c (lollipop) screen looks ok
But in micromax canves (Ice Cream Sandwich) this problem happens
I want my app look like the same as in my mi4c in every devices.
This is my xml file.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout_widget"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bg_register"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.ceatkelanisrilanka.dushanmadushanka.ceat.CeatMainActivity"
tools:showIn="#layout/activity_ceat_main">
<include
android:id="#+id/app_bar"
layout="#layout/app_toolbar_welcome_menu"></include>
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp">
<LinearLayout
android:id="#+id/enMonth"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingStart="10dp">
<TextView
android:id="#+id/txtMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Month"
android:textColor="#ffffff"
android:textSize="24sp" />
<TextView
android:id="#+id/yearTextV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="year"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:id="#+id/pViewLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<com.rey.material.widget.ProgressView
android:id="#+id/pViewew"
cpd_strokeColor="#android:color/holo_red_dark"
cpd_strokeSecondaryColor="#android:color/holo_blue_bright"
cpd_strokeSize="25dp"
android:layout_width="50dp"
android:layout_height="50dp"
app:pv_autostart="true"
app:pv_circular="true"
app:pv_progressMode="indeterminate"
app:pv_progressStyle="#style/Material.Drawable.CircularProgress" />
</LinearLayout>
<LinearLayout
android:id="#+id/snMonthLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical"
android:paddingEnd="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/txtMonthSn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="MonthSn"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/secondLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="15dp">
<com.github.lzyzsd.circleprogress.ArcProgress
android:id="#+id/arc_progress"
android:layout_width="220dp"
android:layout_height="220dp"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="vertical"
android:paddingRight="15dp"
android:paddingTop="25dp">
<com.hookedonplay.decoviewlib.DecoView
android:id="#+id/dynamicArcView"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="5dp" />
<TextView
android:id="#+id/pView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0 %"
android:textColor="#4B73C4"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Precentage"
android:textColor="#4B73C4"
android:textSize="15sp" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/thirdLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingTop="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/txtMtar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monthly Target"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/txtMAch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Achievment"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/txtPre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Percentage"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.1"
android:orientation="vertical"
android:paddingTop="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtTarget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtAchievement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtCollection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingTop="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/bTon"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Ton"
android:textColor="#color/border_gray" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/bValue"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Value"
android:textColor="#color/border_gray" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/bCollection"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Collection"
android:textColor="#color/border_gray" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="com.ceatkelanisrilanka.dushanmadushanka.ceat.fragments.NavigationDrawerFragment"
android:layout_width="#dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer"></fragment>
</android.support.v4.widget.DrawerLayout>
Try This:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout_widget"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<include
android:id="#+id/app_bar"
layout="#layout/app_toolbar_welcome_menu"></include>
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp">
<LinearLayout
android:id="#+id/enMonth"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingStart="10dp">
<TextView
android:id="#+id/txtMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Month"
android:textColor="#ffffff"
android:textSize="24sp" />
<TextView
android:id="#+id/yearTextV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="year"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:id="#+id/pViewLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<com.rey.material.widget.ProgressView
android:id="#+id/pViewew"
cpd_strokeColor="#android:color/holo_red_dark"
cpd_strokeSecondaryColor="#android:color/holo_blue_bright"
cpd_strokeSize="25dp"
android:layout_width="50dp"
android:layout_height="50dp"
app:pv_autostart="true"
app:pv_circular="true"
app:pv_progressMode="indeterminate"
app:pv_progressStyle="#style/Material.Drawable.CircularProgress" />
</LinearLayout>
<LinearLayout
android:id="#+id/snMonthLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical"
android:paddingEnd="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/txtMonthSn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="MonthSn"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/secondLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:padding="5dp">
<com.github.lzyzsd.circleprogress.ArcProgress
android:id="#+id/arc_progress"
android:layout_width="220dp"
android:layout_height="220dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_weight=".5"
android:gravity="center"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:padding="5dp">
<com.hookedonplay.decoviewlib.DecoView
android:id="#+id/dynamicArcView"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="5dp" />
<TextView
android:id="#+id/pView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0 %"
android:textColor="#4B73C4"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Precentage"
android:textColor="#4B73C4"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/thirdLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingTop="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/txtMtar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monthly Target"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/txtMAch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Achievment"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/txtPre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Percentage"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingTop="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtTarget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtAchievement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtCollection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="M"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:paddingTop="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/bTon"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Ton"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/bValue"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Value"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/bCollection"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Collection"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!--<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="com.ceatkelanisrilanka.dushanmadushanka.ceat.fragments.NavigationDrawerFragment"
android:layout_width="#dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer"></fragment>-->
</android.support.v4.widget.DrawerLayout>
I want to do this:
The problem: all of the layout is contain by ScrollView into a LinearLayout and at the bottom must be the buttons of the stepper. To do that i used layout_weight to locating the elements in the space how i want.
Here is my XML code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
android:background="#drawable/shape_fondo"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:src="#mipmap/indicador_wizzard2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Días de ingesta"
android:layout_marginBottom="6dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
android:weightSum="49">
<ToggleButton
android:id="#+id/lunes"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/botonesdias"
android:textOn="Lu"
android:textOff="Lu"/>
<ToggleButton
android:id="#+id/martes"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/botonesdias"
android:textOn="Ma"
android:textOff="Ma"/>
<ToggleButton
android:id="#+id/miercoles"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/botonesdias"
android:textOn="Mie"
android:textOff="Mie"/>
<ToggleButton
android:id="#+id/jueves"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/botonesdias"
android:textOn="Jue"
android:textOff="Jue"/>
<ToggleButton
android:id="#+id/viernes"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/botonesdias"
android:textOn="Vie"
android:textOff="Vie"/>
<ToggleButton
android:id="#+id/sabado"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/botonesdias"
android:textOn="Sa"
android:textOff="Sa"/>
<ToggleButton
android:id="#+id/domingo"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/botonesdias"
android:textOn="Do"
android:textOff="Do"/>
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2.3"
android:id="#+id/contenedortitulito">
<TextView
android:id="#+id/titulohora"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_alignParentLeft="true"
android:text="Hora" />
<TextView
android:id="#+id/titulodosis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_alignParentRight="true"
android:text="Dosis"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/listview"
android:background="#color/azul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/contenedortitulito"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
style="#style/botones"
android:id="#+id/btn_cancelar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Atrás"
android:layout_gravity="center"/>
<Button
style="#style/botones"
android:id="#+id/btn_irapaso3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Continuar"
android:layout_gravity="center" />
</LinearLayout>
</LinearLayout>
</ScrollView>
I do not quite understand the concept of layout weight. Can you explain me?
Thanks!
You Need to provide weightsum to parent layout first of all after that you can distribute weight accordingly..
i have provided example of screen in which i used weightsum and layout_weight.
You can apply layout weight on scrollview as well
Here is the code for sample screen.
You can ignore first relative layout.
Hope it Helps
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/whole_bg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="35dp"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".15"
android:background="#drawable/top"
android:orientation="horizontal"
android:weightSum="6">
<ImageView
android:id="#+id/ivHome"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ll_home" />
<ImageView
android:id="#+id/ivTraderList"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ll_traderlist_green" />
<ImageView
android:id="#+id/ivStatement"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ll_statement_green" />
<ImageView
android:id="#+id/ivSummary"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ll_summary_green" />
<ImageView
android:id="#+id/ivProduct"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ll_product_green" />
<ImageView
android:id="#+id/ivLogout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ll_logout" />
</LinearLayout>
<TextView
style="#style/TitleStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="#string/trader_list_str" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/lightGreen"
android:orientation="horizontal"
android:weightSum="1">
<EditText
android:id="#+id/etDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".495"
android:editable="false"
android:focusable="false"
android:gravity="center"
android:text="#string/date_str"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
<View
android:layout_width="0dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_weight=".005"
android:background="#android:color/darker_gray" />
<EditText
android:id="#+id/etTime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".495"
android:editable="false"
android:focusable="false"
android:gravity="center"
android:text="#string/time_str"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".84"
android:orientation="vertical"
android:weightSum="1">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".8" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".2"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#color/lightYellow"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/tvLabelTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".595"
android:gravity="center"
android:text="#string/total_str"
android:textAppearance="?android:textAppearanceMedium" />
<View
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:layout_weight=".01"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/tvTotal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="1dp"
android:layout_weight=".395"
android:gravity="center" />
</LinearLayout>
<TextView
android:id="#+id/tvOrder"
style="#style/BtnStyle"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:onClick="placeOrder"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="#string/place_order_str" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/advtLabel"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_alignParentBottom="true"
android:background="#color/lightYellow"
android:orientation="horizontal" />
When the items that I used started to fill whole screen I decided to use scrollview,but when I use it,ScrollView compressing the layouts of items and put them in a smaller part of screen as the following:
And here is my xml.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#A4A4A4">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="40dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:id="#+id/image_button"
android:layout_width="40dp"
android:layout_height="48dp"
android:layout_marginRight="-9dp"
android:src="#drawable/home_ico"
/>
<Button
android:id="#+id/internet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="9sp"
android:layout_marginRight="-9dp"
android:text="#string/internet"
android:textColor="#ffffff"
android:layout_weight="1"/>
<Button
android:id="#+id/servisler"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="9sp"
android:layout_marginRight="-9dp"
android:text="#string/servisler"
android:textColor="#ffffff"
android:layout_weight="1"/>
<Button
android:id="#+id/kampanya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="9sp"
android:layout_marginRight="-9dp"
android:text="#string/kampanya"
android:textColor="#ffffff"
android:layout_weight="1"/>
<Button
android:id="#+id/hakkımızda"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="9sp"
android:layout_marginRight="-9dp"
android:text="#string/hakkımızda"
android:textColor="#ffffff"
android:layout_weight="1"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="9sp"
android:layout_marginRight="-9dp"
android:textColor="#ffffff"
android:text="Diğer" />
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="0.5">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.8">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
/>
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicator"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:gravity="bottom"
android:padding="5dp"
app:centered="true"
app:fillColor="#ff0099"
app:pageColor="#FF0000"
app:snap="false" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:orientation="vertical">
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="#string/textView4"/>
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="#string/textView5"/>
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="#string/textView6"/>
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="#string/textView7"/>
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="#string/textView8"/>
<TextView
android:id="#+id/textView9"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="#string/textView9"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FF0000FF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="wefwfw"/>
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:drawable="#drawable/adsl"/>
<TextView
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="qwgq"/>
<TextView
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="qwgq"/>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#FF0000FF" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="wefwfw"/>
<ImageView
android:id="#+id/image2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:drawable="#drawable/adsl"/>
<TextView
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="qwgq"/>
<TextView
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="qwgq"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FF0000FF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="wefwfw"/>
<ImageView
android:id="#+id/image3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:drawable="#drawable/adsl"/>
<TextView
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="qwgq"/>
<TextView
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="qwgq"/>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#FF0000FF" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="vertical">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="wefwfw"/>
<ImageView
android:id="#+id/image4"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:drawable="#drawable/adsl"/>
<TextView
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="qwgq"/>
<TextView
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="qwgq"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#FF0000FF" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
So what is my problem?
Thanks in advance...
I have the followin xml where I want imageview and then two textview and then imageview again, but it does not work properly.
Here is what I planned to have:
Here is what I am getting:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:clickable="true"
android:onClick="userProfileDetailAction"
android:id="#+id/userProfileDetail"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<com.example.eyeniaras.satdostum.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_weight="0.3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/circle_shape"
app:civ_border_width="0.2dp"
app:civ_border_color="#color/dark"
android:id="#+id/userImage"
android:scaleType="centerCrop"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6">
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:layout_weight="1"/>
<TextView
android:id="#+id/userRegistrationDate"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:text = "45 days ago"
android:layout_weight="1"/>
</LinearLayout>
<ImageView
android:id="#+id/userClick"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.1"
android:background="#drawable/list_arrow" />
</LinearLayout>
inside linearlayout must have 0 width
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:weightSum="100"
android:layout_weight="60">
Inside linearlayout second chance follow code.
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="60">
i was changed your code check it
change image View as you require and replace your code with this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:clickable="true"
android:weightSum="100"
android:onClick="userProfileDetailAction"
android:id="#+id/userProfileDetail"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<ImageView
android:layout_weight="20"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/userImage"
android:src="#android:drawable/btn_star_big_on"
android:scaleType="centerCrop"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:weightSum="100"
android:gravity="center_vertical"
android:layout_weight="60">
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center" android:text="hey hi"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:textStyle="bold"
android:layout_weight="50"/>
<TextView
android:id="#+id/userRegistrationDate"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:text = "45 days ago"
android:textStyle="bold"
android:layout_weight="50"/>
</LinearLayout>
<ImageView
android:id="#+id/userClick"
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#android:drawable/btn_star"
android:layout_weight="20" /></LinearLayout>
it is because of width make it 0dp..copy the bellow code it works perfect
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:clickable="true"
android:weightSum="100"
android:onClick="userProfileDetailAction"
android:id="#+id/userProfileDetail"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<com.example.eyeniaras.satdostum.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_weight="20"
android:layout_width="0dp"
android:layout_height="10dp"
android:background="#drawable/circle_shape"
app:civ_border_width="0.2dp"
app:civ_border_color="#color/dark"
android:id="#+id/userImage"
android:scaleType="centerCrop"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:orientation="vertical"
android:layout_height="match_parent"
android:weightSum="100"
android:layout_weight="60">
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:textStyle="bold"
android:layout_weight="50"/>
<TextView
android:id="#+id/userRegistrationDate"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:text = "45 days ago"
android:textStyle="bold"
android:layout_weight="50"/>
</LinearLayout>
<ImageView
android:id="#+id/userClick"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold"
android:layout_weight="20"
android:background="#drawable/list_arrow" />
</LinearLayout>
You can use The following Code:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5"
android:gravity="center"
android:text="hello" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5"
android:gravity="center"
android:text="hello" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
This is the perfect scenario to make use of PercentageRelativeLayout. The best thing about this layout is that you can use percentage based dimensions which is super easy.
Here is a quick example of it,
<android.support.percent.PercentRelativeLayout
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">
<ImageView
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="25%"
app:layout_marginLeftPercent="25%"/>
</android.support.percent.PercentFrameLayout>
This is very simple and intuitive to use and is optimized for various use cases too.
I've taken your code and stripped it down. The following, at least in studio design, has the layout you've described. Perhaps progressively change/adapt this; checking as you go along that it maintains the desired layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:clickable="true"
android:weightSum="100"
android:onClick="userProfileDetailAction"
android:id="#+id/userProfileDetail"
android:paddingTop="5dp"
android:paddingBottom="5dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="500dp"
android:layout_height="100dp"
android:weightSum="100"
android:layout_weight="60">
<TextView
android:id="#+id/userName"
android:layout_width="500dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:textStyle="bold"
android:layout_weight="50"/>
<TextView
android:id="#+id/userRegistrationDate"
android:layout_width="500dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:text = "45 days ago"
android:textStyle="bold"
android:layout_weight="50"/>
</LinearLayout>
<ImageView
android:id="#+id/userClick"
android:layout_width="100dp"
android:layout_height="100dp" />
</LinearLayout>
Note I've done away with things like width="match_parent", which may have been an issue, as an example.
According to Image.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/userProfileDetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:onClick="userProfileDetailAction"
android:orientation="horizontal"
android:padding="5dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="5">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<com.example.eyeniaras.satdostum.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/userImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/circle_shape"
android:scaleType="centerCrop"
app:civ_border_color="#color/dark"
app:civ_border_width="0.2dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical"
android:weightSum="2">
<TextView
android:id="#+id/userName"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#ffffff"
android:text="45 days ago"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/userRegistrationDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:text="45 days ago"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="#+id/userClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="20"
android:background="#drawable/list_arrow"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
Don't use weightsum at all and then assign weight according to requirement to all main views.It will definitely work.why to make things complex.I have done it for you.Check it below.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:clickable="true"
android:onClick="userProfileDetailAction"
android:id="#+id/userProfileDetail"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<com.example.eyeniaras.satdostum.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_weight="0.2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#drawable/circle_shape"
app:civ_border_width="0.2dp"
app:civ_border_color="#color/dark"
android:id="#+id/userImage"
android:scaleType="centerCrop"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6">
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:textStyle="bold"
android:layout_weight="1"/>
<TextView
android:id="#+id/userRegistrationDate"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:background="#ffffff"
android:textSize="18sp"
android:text = "45 days ago"
android:textStyle="bold"
android:layout_weight="1"/>
</LinearLayout>
<ImageView
android:id="#+id/userClick"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold"
android:layout_weight="0.2"
android:background="#drawable/list_arrow" />
</LinearLayout>
you need to use android:layout_weight for both images and textview so here is solution,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/userProfileDetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:clickable="true"
android:onClick="userProfileDetailAction"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="5">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.4">
<com.example.eyeniaras.satdostum.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/userImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/circle_shape"
android:scaleType="centerCrop"
app:civ_border_color="#color/dark"
app:civ_border_width="0.2dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical"
android:weightSum="2">
<TextView
android:id="#+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:text="Hi"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/userRegistrationDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#ffffff"
android:gravity="center"
android:text="45 days ago"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6">
<ImageView
android:id="#+id/userClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="20"
android:background="#drawable/list_arrow"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:layout_weight="60">
android:layout_width="match_parent",this layout's width is match_parent,so it filled up everything else,change to wrap_content,just like
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/userProfileDetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:onClick="userProfileDetailAction"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:weightSum="100" >
<ImageView
android:id="#+id/userImage"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="20"
android:background="#drawable/ic_launcher"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:weightSum="100"
android:layout_weight="60"
android:orientation="vertical"
>
<TextView
android:id="#+id/userName"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="50"
android:background="#ffffff"
android:text="46 days ago"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/userRegistrationDate"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="50"
android:background="#ffffff"
android:text="45 days ago"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="#+id/userImage"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="20"
android:background="#drawable/ic_launcher"
android:scaleType="centerCrop"
/>
</LinearLayout>
use can following thing for weight ..i think this answer is helpful for you..
this xml
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:background="#drawable/background"
android:gravity="center" >
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/images" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="40" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="#drawable/background"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Firstname" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="#drawable/background"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lastname" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:background="#drawable/background"
android:gravity="center" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/download" />
</LinearLayout>
</LinearLayout>
and this code for background past in drawable/background
<?xml version="1.0" encoding="UTF-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="12dp"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<stroke
android:width="0.3dp"
android:color="#797979" />`enter code here`
</shape>