5

I have following layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/item_background"
    android:layout_margin="10dip"
    android:gravity="center_vertical">

    <View
        android:layout_width="30dip"
        android:layout_height="fill_parent"
        android:background="@color/test_color"/>

    <ImageView
        android:id="@+id/task_item_startstop_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/start_task"
        android:layout_centerVertical="true"
        android:focusable="false"
        android:background="#0000"/>

    <View
        android:id="@+id/task_item_line"
        android:layout_width="2dp"
        android:layout_height="40dip"
        android:layout_margin="5dip"
        android:background="@color/line_color"
        android:layout_toRightOf="@id/task_item_startstop_button"/>

    <TextView
        android:id="@+id/task_item_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/black"
        android:textSize="22sp"
        android:textStyle="bold"
        android:layout_toRightOf="@id/task_item_line" />

    <TextView
        android:id="@+id/task_item_status"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/task_item_suspended"
        android:textSize="18sp"
        android:textColor="@android:color/black"
        android:layout_toRightOf="@id/task_item_line"
        android:layout_below="@id/task_item_title"/>

    <TextView
        android:id="@+id/task_item_timer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:textSize="18sp"
        android:textColor="@android:color/black"
        android:layout_toRightOf="@id/task_item_status"
        android:layout_below="@id/task_item_title"/>

</RelativeLayout>

I want to have vertical line (first view inside root layout) on th left of layout with fixed width and height equal parent's height. But if I set layout_height="fill_parent" it doesn't help. Height is 0. If I set height for example 40dip, it will be 40 dip. But I need exactly fill_parent property.

Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128
Dmitriy
  • 830
  • 3
  • 15
  • 29
  • Can you post a drawing of what you want to achieve? – Aleks G Jul 13 '12 at 08:30
  • Try this, use android:layout_alignParentLeft="true" for your View and then set task_item_startstop_button relative to it. GIve an id to ure View – Shubhayu Jul 13 '12 at 08:30
  • @AleksG I need have vertical strip on the left of this layout – Dmitriy Jul 13 '12 at 09:38
  • 1
    @Shubhayu it didn't help – Dmitriy Jul 13 '12 at 09:38
  • Try using `hierarchyviewer` to see exactly what is being layed out and where the sizes do not match. It is often not the component you're blaming but rather its parent or even "grandparent" – Aleks G Jul 13 '12 at 09:40
  • @Dmitry are u facing this problem in the graphical view of eclipse? I tried your code and i could see the bar on the left. Though i have not run it on a device or the emulator – Shubhayu Jul 13 '12 at 10:04
  • 1
    Hey i m also facing same issue, i need left side strip but the above code i tried its not working any clue why view does not take fill_parent for height property?, if i hard code height as 10 or 20 dip it works. – Naruto Oct 14 '13 at 15:29
  • Maybe this answer will help you: http://stackoverflow.com/a/6902880/289827 – Martin Ždila Oct 22 '13 at 15:16

2 Answers2

0

Does this solve your problem? Just replace the relevant elements with your own

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

        <Button 
            android:layout_height="match_parent"
            android:layout_width="30dp"
            android:id="@+id/thebutton"
            android:text="hello world"
            />

    <AnalogClock
        android:id="@+id/analogClock1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/thebutton" />

</RelativeLayout>
Jon
  • 7,941
  • 9
  • 53
  • 105
-1

you have given margin to your Parent relative layout, that's why whenever you add anything it always give margin to your widgets. Remove android:layout_margin="10dip" from your parent relative layout then you got line which comes in fil parent.

Kimmi Dhingra
  • 2,249
  • 22
  • 21