Suppose there is an XML Layout like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="horizontal"
android:paddingLeft="#dimen/margin_medium" >
<TextView
android:id="#+id/title"
style="#style/label_text_dark"
android:layout_width="0dp"
android:layout_height="______h1_____"
android:layout_weight="8"
android:gravity="center_vertical" />
<View
android:id="#+id/v_line"
android:layout_width="#dimen/margin_extra_small"
android:layout_height="______h2_____"
android:background="#color/light_gray" />
which eventually results to this:
so the question: is there a way to bind h2 to h1 in xml (NOT PROGRAMMATICALLY) so whenever h1 changes h2 changes automatically.
what am I looking for should look similar to this:
<View
android:id="#+id/v_line"
android:layout_width="#dimen/margin_extra_small"
android:layout_height="#+id/title.height"
android:background="#color/light_gray" />
android:layout_height="#+id/title.height" (this of course not works)
NOTE: one of elements can also be outside of parent container, e.g. v_line can be outside of linear layout
thanks in advance
You can do like this-
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_baselineAligned="false"
android:orientation="horizontal"
android:background="#color/white">
<TextView
android:id="#+id/title"
style="#style/label_text_dark"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Last" />
<View
android:id="#+id/v_line"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/light_gray" />
</LinearLayout>
So the solution is to disable baseline alignment for the container view when it is not useful for your application. Then setting the layout weight of each view to be equal.
Also I encourage you to check out this article - shifty-baseline-alignment.
Try to set up this values:
<TextView
android:id="#+id/title"
style="#style/label_text_dark"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="center_vertical" />
<View
android:id="#+id/v_line"
android:layout_width="#dimen/margin_extra_small"
android:layout_height="match_parent"
android:background="#color/light_gray" />
Heigth of LinearLayout is correct.
You can try like this:
<TextView
android:id="#+id/title"
style="#style/label_text_dark"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:gravity="center_vertical" />
<View
android:id="#+id/v_line"
android:layout_width="#dimen/margin_extra_small"
android:layout_height="wrap_content"
android:layout_alignTop="#id/title"
android:background="#color/light_gray" />
alignTop will resize your view as TextView height changes..Good Luck
You can do it using RelativweLayout..Fix the Width of Views as you want
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="horizontal"
android:paddingLeft="#dimen/margin_medium" >
<TextView
android:id="#+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:background="#119283"
android:gravity="center_vertical" />
<View
android:id="#+id/v_line"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/title"
android:layout_weight="3"
android:layout_alignBottom="#+id/title"
android:layout_toRightOf="#+id/title"
android:background="#342748" />
Related
So I want to have a title with 2 buttons next to it. These buttons should stick to the left next to the text, and when the text becomes too long, it should flow on 2 lines.
I was able to replicate this by giving the textView a maxwidth, but this causes the textview to take that maxwidth, even if it reflows on 2 lines. Therefore my buttons don't align next to the text anymore.
Like this:
How can I make my textView take the width it needs, not the one I tell it to use as maxWidth?
Here comes the perfectly working answer using ConstraintLayout (as I love this layout).
This is the code.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text"
android:layout_marginTop="25dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:maxWidth="300dp">
<TextView
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:maxWidth="300dp"
android:text="Some layout is going to be created and whatever I do it won't cross the limit."
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"/>
</android.support.constraint.ConstraintLayout>
<ImageView
android:layout_height="40dp"
android:background="#365987"
android:layout_width="40dp"
android:layout_marginStart="5dp"
android:id="#+id/image"
app:layout_constraintLeft_toRightOf="#+id/text"
app:layout_constraintTop_toTopOf="#+id/text"/>
<ImageView
android:id="#+id/image1"
android:layout_height="40dp"
android:background="#e85f11"
android:layout_width="60dp"
android:layout_marginStart="5dp"
app:layout_constraintBottom_toBottomOf="#+id/image"
app:layout_constraintLeft_toRightOf="#+id/image"
app:layout_constraintTop_toTopOf="#+id/image"/>
</android.support.constraint.ConstraintLayout>
Outputs:
Whatever the text is, it will not cross the maxwidth. And with less width than maxwidth, it's width will be wrap_content.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:text="Male:"
android:textColor="#111111"
android:textSize="12dp" />
<ImageView
android:id="#+id/iv_male"
android:layout_width="#dimen/_42sdp"
android:layout_height="#dimen/_42sdp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:padding="10dp"
android:src="#drawable/block_user" />
<ImageView
android:id="#+id/iv_female"
android:layout_width="#dimen/_42sdp"
android:layout_height="#dimen/_42sdp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:padding="10dp"
android:src="#drawable/blocked_user" />
</LinearLayout>
<TextView
android:id="#+id/tv_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is something Demo Content"
android:layout_marginLeft="#dimen/_15sdp"
android:textColor="#111111"
android:textSize="12dp" />
</LinearLayout>
So you can just add content below the linear layout complete
I Hope it Helps you and you will get your solution.
Try this code
<?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="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:paddingEnd="100dp"
android:text="Simple textdfddfdf dfdfdfdfdf dfdf Sample Text Sample Text" />
<LinearLayout
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/zero"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Here, You have to pass android:paddingEnd="100dp". This you can manage from dimens.xml
I hope. This will help full
You should use ConstraintLayout
compile 'com.android.support.constraint:constraint-layout:1.0.2'
Let's take an instance of that Planner part of the image.
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/constraintLayout"
<!-- Other attributes -->
<TextView
android:id="#+id/text"
android:layout_width = "xxxdp"
android:layout_height = "xxxdp"
app:layout_constraintBottom_toBottomOf="#+id/constraintLayout"
app:layout_constraintLeft_toLeftOf="#+id/constraintLayout"
app:layout_constraintTop_toTopOf="#+id/constraintLayout"
<!-- Other attributes --> />
<ImageView
android:id="#+id/image1"
app:layout_constraintBottom_toBottomOf="#+id/text"
app:layout_constraintLeft_toRightOf="#+id/text"
app:layout_constraintTop_toTopOf="#+id/text"
<!-- Other attributes --> />
<ImageView
android:id="#+id/image1"
app:layout_constraintBottom_toBottomOf="#+id/text"
app:layout_constraintLeft_toRightOf="#+id/image1"
app:layout_constraintTop_toTopOf="#+id/image1"
<!-- Other attributes --> />
Definition of Attributes used.
layout_constraintTop_toTopOf — Align the top of the desired view to the top of another.
layout_constraintBottom_toBottomOf — Align the bottom of the desired view to the bottom of another.
layout_constraintLeft_toRightOf — Align the left of the desired view to the right of another.
I have 2 image views in a linear layout like so:
<LinearLayout
style="#style/home_icon_row"
android:orientation="horizontal">
<ImageView
android:id="#+id/ibtn_home_bus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ico_bus_selector" />
<ImageView
android:id="#+id/ibtn_home_butoday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ico_butoday_selector" />
</LinearLayout>
How can i align the two images so that they are evenly placed within the linear layout. Something similar to "justified text" so that it has equal spacing on the left and right of the image from each other and the border of the screen.
it's not the best solution, but it should work:
<LinearLayout
style="#style/home_icon_row"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="0dp"
android:enable="false"
android:focussable="false"
android:clickable="false"
/>
<ImageView
android:id="#+id/ibtn_home_bus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ico_bus_selector" />
<View
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="0dp"
android:enable="false"
android:focussable="false"
android:clickable="false" />
<ImageView
android:id="#+id/ibtn_home_butoday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ico_butoday_selector" />
<View
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="0dp"
android:enable="false"
android:focussable="false"
android:clickable="false" />
</LinearLayout>
if this is for some kind of landing it's ok but if it's a hard used layout think about implementing it dinamically via javacode to make it faster.
EDIT: i added 3 attributes ( enable, focussable, clickable ) to disable the placehodler view so that they'll be considered only at measures/layout time, but not during events handling.
// try this way here is alternative to use two sub linear layout rather three View.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/home_icon_row"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/ibtn_home_bus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ico_bus_selector" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/ibtn_home_butoday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ico_butoday_selector" />
</LinearLayout>
</LinearLayout>
You should be able to get similar effect by using layout_width="0dp", layout_weight="1" and scaleType="centerInside" for both ImageViews.
The only difference is that space between the images can be bigger.
<LinearLayout
style="#style/home_icon_row"
android:orientation="horizontal"
android:padding="#dimen/padding">
<ImageView
android:id="#+id/ibtn_home_bus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ico_bus_selector"
android:layout_marginRight="#dimen/padding"/>
<ImageView
android:id="#+id/ibtn_home_butoday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ico_butoday_selector" />
</LinearLayout>
This is my custom dialog, there are some textboxs and two buttons.
I'm using a RelativeLayout on it.
I'd like the dialog size to match the content, not all that blank space under there.
I don't want to use explicit pixel heights (it's not good practice).
Another thing, there's a way to have some space between every view?
This is my XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/txt_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:textStyle="italic" />
<TextView
android:id="#+id/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_below="#+id/txt_desc"
android:textSize="8pt" />
<TextView
android:id="#+id/txt_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_below="#+id/txt_date"
android:textSize="8pt" />
<Button
android:id="#+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/txt_place"
android:layout_toRightOf="#+id/view"
android:text="#string/btn_close" />
<View
android:id="#+id/view"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txt_place"
android:layout_toLeftOf="#+id/view"
android:drawableLeft="#android:drawable/ic_menu_edit"
android:text="#string/btn_edit" />
</RelativeLayout>
First question
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
Second question
Plus use android:marginTop="5dp" if you want to separate a View from Top for 5 dp.
marginLeft|Right|Bottom are also available.
<TextView
android:id="#+id/txt_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp" <-----------------
android:layout_below="#+id/txt_date"
android:textSize="8pt" />
By the way, if I were you, I'd nest some layouts to make order. You can have a general Relative Layout, then 2 linear layouts: one horizontal for TextViews and one vertical for Buttons. You can definely play with your editor and try to make the best appearance for your dialog.
EDIT
Try this one:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000"
android:orientation="vertical"
android:paddingBottom="50dp" >
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="prova"
android:textSize="8pt"
android:textStyle="italic" />
<TextView
android:id="#+id/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="prova"
android:textSize="8pt" />
<TextView
android:id="#+id/txt_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="prova"
android:textSize="8pt" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/ic_menu_edit"
android:text="btn_edit" />
<Button
android:id="#+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn_close" />
<View
android:id="#+id/view"
android:layout_width="0dp"
android:layout_height="1dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I've hard-coded the texts. The main idea is to use a big container layout in background, which is trasparent (background=#0000) and in top of that a layout in wrap_content containing your Views.
If this solution doesn't resolve your problem, I think you could edit height directly in your code. Try to relate to this question
Set your relative layout's height to wrap_content.
For example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- More XML -->
</RelativeLayout>
Also be aware that fill_parent is deprecated for widths and heights.
You can add either margin (extra space outside a view) or padding (extra space inside a view) with android:layout_margin or android:padding respectively. There are also variants such as layout_marginTop that only apply to a specific side of the view.
I want to display three different values allocated to two different headers, in other words a first header with one value and a second one with two values
My approach is to split the "header linear layout" 40/60 and the "values linear layout" 40/30/30. In order to not display the text beginning at the border, I put everywhere an android:layout_marginLeft="15dp" in, so finally it should remain proportional.
In my XML, I declare the following:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_weight="4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="#string/txt_price_chf"
/>
<TextView
android:layout_weight="6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="#string/txt_price_offshore_chf"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="#+id/tv_price_ch"
android:layout_weight="4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Value1"
/>
<TextView android:id="#+id/tv_price_off_chf"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Value2"
/>
<TextView android:id="#+id/tv_price_off_eur"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Value3"
/>
</LinearLayout>
The result is following output:
Why are the "Price offshore:"-TextView and the "Value2"-TextView not in line? Note that "Price offshore" is saved in my strings.xml, there is no error like a whitespace or something. First I thought, it's caused by the android:layout_marginLeft="15dp", but
how I understood it the "dp" is a relative value to a specific
resolution (so the split-off by android:layout_weigth should not
effect this) and
if I remove the margins, they are still not in
line.
Has anyone an idea? Do I overlook something obvious?
<TextView
android:layout_weight="4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="-10dp"
android:text="#string/txt_price_chf"
/>
This will work for you...
Not really something you should be doing with a LinearLayout though.
I suggest using a RelativeLayout, there you can just say that those two should align.
Without digging into details in this particular case, it can be either marginRight, padding etc or just simply a side effect of the non monospaced font.
Or another alternative is this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight=".60"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="txt_price_chf" />
<TextView
android:id="#+id/tv_price_ch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight=".40"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="txt_price_offshore_chf" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tv_price_off_chf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Value2" />
<TextView
android:id="#+id/tv_price_off_eur"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Value3" />
</LinearLayout>
</LinearLayout>
I have a layout like this in which I want to display a label above a view and then repeat it below.
Here is my code...
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/speedLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="#string/speed"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:id="#+id/speedGraph"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_below="#+id/speedLbl"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#color/blueColour" />
<TextView
android:id="#+id/distanceLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_below="#+id/speedGraph"
android:text="#string/distance"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:id="#+id/distanceGraph"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#+id/distanceLbl"
android:layout_marginBottom="4dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#color/blueColour" />
</RelativeLayout>
The problem is I don't want to set a height for the two views as I want them to dynamically change depending on the screen size. I tried using layout_weight but it doesn't like the fact that its nested inside another.
Can anyone see another solution for this problem??
You could avoid the double weights issue with a small trick. You could set an empty View at the vertical center of the parent RelativeLayout and position the two groups above and below that View, something like this:
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<View android:id="#+id/anchor"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_centerVertical="true/>
<TextView
android:id="#+id/speedLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="#string/speed"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:id="#+id/speedGraph"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_below="#id/speedLbl"
android:layout_above="#id/anchor"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#color/blueColour" />
<TextView
android:id="#+id/distanceLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_below="#id/anchor"
android:text="#string/distance"
android:textAppearance="?android:attr/textAppearanceLarge" />
<View
android:id="#+id/distanceGraph"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#id/distanceLbl"
android:layout_alignParentBottom="true"
android:layout_marginBottom="4dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#color/blueColour" />
</RelativeLayout>
Also you should use the #+id/... notation only when you first declare that id, on the next id occurrence you should use #id/....
You can achieve the dynamic screen size through layout_weight . But before that you just try layout_weight to the Linear Layout and provide the appropriate weights to the view and textview. It almost solve your problem. Dont use Relative Layout with Weight. weight is not working in Relative layout.