java - 带有 MATCH_PARENT 的 RelativeLayout 不起作用

标签 java android android-relativelayout

这是我想要实现的目标: 我有很多表行的表。每行应该有两个 TextView ,产品标题和副标题在彼此之上(副标题尚未实现)。应该左对齐。在右边,我想要一个微调器来选择数量。

文本来自数据库,当然长度不一。

这是我到目前为止的想法:

<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>

截图:

enter image description here

第一个问题是 RelativeLayout 没有填满表格行的宽度。第二个问题:微调器没有正确对齐。

我错过了什么?

最好的问候 艾伦

最佳答案

android:fillViewport="true"

将这一行添加到您的 ScollView 属性中,您就完成了:)

关于java - 带有 MATCH_PARENT 的 RelativeLayout 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10290072/

相关文章:

java - 如何将 RelativeLayout(来自 XML)添加到我以编程方式定义的 LinearLayout?

android - 我的 2 个按钮在左下角,不知道为什么?

java - 将 "_<digit>string"与正则表达式匹配

java - 确定路径字符串是 Java 的本地机器还是远程机器的方法

java - 回收器 View : Changing background color of a Textview on each List Item

Android:按百分比排名?

java - 解析 XML 时出现 IllegalStateException?

java - Jasper 时间序列日期轴 : show monthly ticks but yearly tick labels

java - 通过 http 下载 Google Drive 文件

android - 如果在 exoplayer 中第一个出现错误,我可以播放第二个媒体源吗?