Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RelativeLayout with MATCH_PARENT doesn't work

Here's what I want to achieve: I have at table with a lot of table rows. Each row should have two text view with a product title and subtitle on top of each other (subtitle not implementet yet). The should be left aligned. To the right I want a spinner to select the quantity.

The texts come from the database and are of course of different lengths.

Here is what I've come up with so far:

<ScrollView android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

   <TableLayout 
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/barmenu"
      android:background="#99ffff"
      android:scrollbars="vertical">

      <TableRow 
         android:layout_height="wrap_content" 
         android:background="#ffff99"
         android:layout_width="match_parent">

         <RelativeLayout
            android:layout_width="match_parent"
            android:background="#0000ff">

            <TextView
               android:id="@+id/productTitle"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:background="#88ffff"
               android:ellipsize="end"
               android:padding="2dp"
               android:singleLine="true"
               android:text="Product name"
               android:textColor="#000000"
               android:gravity="left" 
               android:textSize="13sp"
               android:textStyle="bold" />

            <Spinner
               android:gravity="right" 
               android:layout_height="40dp"
               android:layout_toRightOf="@id/productTitle"
               android:width="100dp"
               android:layout_width="wrap_content" /> 
         </RelativeLayout>
      </TableRow>
      <TableRow 
         android:layout_height="wrap_content" 
         android:background="#ffff99"
         android:layout_width="match_parent">

         <RelativeLayout
            android:layout_width="match_parent"
            android:background="#0000ff">

            <TextView
               android:id="@+id/productTitle2"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:background="#88ffff"
               android:ellipsize="end"
               android:padding="2dp"
               android:singleLine="true"
               android:text="Some long long long long name"
               android:textColor="#000000"
               android:gravity="left" 
               android:textSize="13sp"
               android:textStyle="bold" />

            <Spinner
              android:gravity="right" 
              android:layout_height="40dp"
              android:layout_toRightOf="@id/productTitle2"
              android:width="100dp"
              android:layout_width="wrap_content" /> 
         </RelativeLayout>
      </TableRow>
   </TableLayout>
</ScrollView>

Screendump:

enter image description here

First problem is that the RelativeLayout doesn't fill out the width of the table row. And the second problem: the spinners are not right aligned.

What am I missing?

best regards Allan

like image 368
allanth Avatar asked Feb 20 '23 17:02

allanth


2 Answers

android:fillViewport="true"

add this line to your ScollView attributes and you're done :)

like image 106
Ishaan Kumar Avatar answered Feb 28 '23 03:02

Ishaan Kumar


I'd make it simpler and lighter. Just use RelativeLayout for all these 4 views. Align to right both spinners and make textview's with - match_parent and add toLeftOf the relative spinner. I think you will see what you want.

like image 22
Volodymyr Lykhonis Avatar answered Feb 28 '23 01:02

Volodymyr Lykhonis