wazaminator
wazaminator

Reputation: 245

fill parent on a textview doesn't apply

I know this question has been asked multiple times, but I have looked on all the solution I could see and none of them worked. I have a textview inside a relative-layout. the textview has a height : fill_parent atribute that does not work. the pun is that they are severall other textview in this relative-layoutwhich all manage to fill parent,except for this one. here is the XML :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/customshape"
    android:orientation="horizontal" >
    <TextView
        android:id="@+id/mainlistdescription"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:scrollHorizontally="true"
        android:maxLines="4"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/mainlistquantite"
        android:layout_gravity="center_vertical"
        android:textSize="12sp"
        android:padding="10dp"
         />
<TextView
        android:id="@+id/mainlistquantite"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:maxLines="4"
        android:layout_toLeftOf="@+id/consultaffichelayoutdroit"
        android:textSize="12sp"
        android:padding="10dp"
         />
<TextView
        android:id="@+id/consultafficheseparator" <!-- the one not working-->
        android:layout_width="2dp"
        android:layout_height="fill_parent"
        android:layout_toLeftOf="@+id/imageView1"
        android:background="#777777"
        android:maxWidth="2dp" />
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="15dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:gravity="center_vertical|right"
        android:src="@drawable/fleche" /> 
    <LinearLayout
        android:id="@+id/consultaffichelayoutdroit"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_toLeftOf="@+id/consultafficheseparator"
        android:orientation="vertical"
        android:paddingLeft="5dp"
         >
        <TextView
            android:id="@+id/mainlistnumero"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_gravity="right"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:textSize="12sp"
            android:textStyle="bold" />
        <TextView
            android:id="@+id/mainlistprix"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_gravity="right"
            android:layout_marginRight="10dp"
            android:layout_weight="1" />
    </LinearLayout>
</RelativeLayout>

here is what i get : enter image description here

the grey bar should go all the way but doesn't when actually running on the emulator( it does in the eclipse tool)

since this xml is actually called in a list view, I can't seem to fix the problem using JAVA code, so the solution would ideally be on the XML file. I tryed so far android:clipChildren="false" without sucess, as well as changing the order of my elements in the XML, wich juste made it worse.

after experiment,I can tell nothing takes the place so it's not the it cannot go because there is allready a view there,it just doesn't expand that far

thanks for the help on that

Upvotes: 2

Views: 2618

Answers (7)

Jelle
Jelle

Reputation: 919

Why are you using a TextView to draw a separator? Try with a normal view like the code below.

Also, if the seperator has to align to the bottom of your description view, you can use the layout_alignBottom-property of RelativeLayout like this:

android:layout_alignBottom="@+id/mainlistdescription"

So the separator would look something like the code below:

<View
     android:id="@+id/consultafficheseparator"
     android:layout_width="2dp"
     android:layout_height="match_parent"
     android:layout_toLeftOf="@+id/imageView1"
     android:layout_alignBottom="@+id/mainlistdescription"
     android:background="@color/separator_bg" />

Below some other tips:

  1. It's better to define a color in some resource-file (eg. colors.xml) and refer to that color from inside your layout. Especially when using it in a ListView

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="separator_bg">#777777</color>
    </resources>
    

    And in your layout-file android:background="@color/separator_bg"

  2. Use match_parent instead of fill_parent because that's deprecated.

  3. I see android:scrollHorizontally="true" on one of the TextView's. That only works when the TextView is editable. If you want the content to scroll because it doesn't fit in the TextView, try to use the code below:

    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    

    And in your adapter.getView():

    final TextView description = (TextView) view.findViewById(R.id.mainlistdescription);
    description.setSelected(true);
    

Upvotes: 3

Mit Bhatt
Mit Bhatt

Reputation: 1645

1)Try to make your Linear Layout orientation vertical or 2)Try to make your Relative Layout orientation vertical

it can be help.

Upvotes: 0

Sagar Waghmare
Sagar Waghmare

Reputation: 4742

This is what you should do,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/customshape"
android:orientation="horizontal" >
<TextView
    android:id="@+id/mainlistdescription"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:scrollHorizontally="true"
    android:maxLines="4"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@+id/mainlistquantite"
    android:layout_gravity="center_vertical"
    android:textSize="12sp"
    android:padding="10dp"
     />
<TextView
    android:id="@+id/mainlistquantite"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:maxLines="4"
    android:layout_toLeftOf="@+id/consultaffichelayoutdroit"
    android:textSize="12sp"
    android:padding="10dp"
     />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="15dp"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:gravity="center_vertical|right"
    android:src="@drawable/fleche" /> 
<TextView
    android:id="@+id/consultafficheseparator" <!-- this will work now -->
    android:layout_width="2dp"
    android:layout_height="fill_parent"
    android:layout_toLeftOf="@+id/imageView1"
    android:background="#777777"
    android:maxWidth="2dp" />
<LinearLayout
    android:id="@+id/consultaffichelayoutdroit"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_toLeftOf="@+id/consultafficheseparator"
    android:orientation="vertical"
    android:paddingLeft="5dp"
     >
    <TextView
        android:id="@+id/mainlistnumero"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="right"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:textSize="12sp"
        android:textStyle="bold" />
    <TextView
        android:id="@+id/mainlistprix"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="right"
        android:layout_marginRight="10dp"
        android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>

Upvotes: 0

Rodion Altshuler
Rodion Altshuler

Reputation: 1783

It's very strange you get such view of this layout, because after copy&paste of your layout code I've got this one.

Your solution works, I've made some minor improvments. It's like your code, but there is no need to use TextView if you need background color only, View could be used instead.

<View
     android:id="@+id/consultafficheseparator"
     android:layout_width="2dp"
     android:layout_height="match_parent"
     android:layout_toLeftOf="@+id/imageView1"
     android:background="#777777"
/>

Only suggestion is to set root layout height "match_parent" or some value in dp, like thiagolr proposed. I've set it to "100dp" for this screenshot.

screenshot

Upvotes: 0

thiagolr
thiagolr

Reputation: 7027

Try setting one (or all) of the following to see if it changes anything:

android:maxHeight="100dp"

or

android:layout_height="100dp"

or

android:text="a"
android:textColor="#777777"

If any of these options change the size, please let me know and we can work on a proper solution!

Upvotes: 0

ABT
ABT

Reputation: 347

Had the same pesky problem which by the way makes no sense. What worked for me in the end was changing the android:layout_height in RelativeLayout tag to fill_parent like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background="@drawable/customshape"
    android:orientation="horizontal">

hope this helps

Upvotes: 0

Yoann Hercouet
Yoann Hercouet

Reputation: 17976

It looks like your TextView is not at the top level, maybe you can try the following in your code:

consultafficheseparatorTextView.bringToFront();

Upvotes: 1

Related Questions