简体   繁体   English

使用MATCH_PARENT的RelativeLayout不起作用

[英]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: Screendump:

在此输入图像描述

First problem is that the RelativeLayout doesn't fill out the width of the table row. 第一个问题是RelativeLayout没有填写表格行的宽度。 And the second problem: the spinners are not right aligned. 第二个问题:纺纱厂没有正确对齐。

What am I missing? 我错过了什么?

best regards Allan 最好的问候艾伦

android:fillViewport="true" 机器人:fillViewport = “真”

add this line to your ScollView attributes and you're done :) 将此行添加到您的ScollView属性中,您就完成了:)

I'd make it simpler and lighter. 我会让它更简单,更轻松。 Just use RelativeLayout for all these 4 views. 只需对所有这4个视图使用RelativeLayout Align to right both spinners and make textview's with - match_parent and add toLeftOf the relative spinner. 将两个微调器对齐并使用 - match_parent进行textview,并将相对微调器添加到toLeftOf I think you will see what you want. 我想你会看到你想要的东西。

android:layout_weight="1"到你的relativelayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM