【问题标题】:A view does not show inside a relative layout视图不显示在相对布局中
【发布时间】:2014-06-12 11:35:02
【问题描述】:

我的布局有问题,我无法找出问题所在。 如您所见,相对布局中有一个计时器和一个表格,但计时器没有显示,甚至没有空格。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/firstLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Chronometer
    android:id="@+id/chrono"
    android:textColor="#4169E1"
    android:textSize="20sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/parentLayout"
    android:layout_centerHorizontal="true"
    android:text="Chronometer"
/>
<TableLayout 
    android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
</TableLayout>
</RelativeLayout>

有什么想法吗?

【问题讨论】:

  • 让你的表格布局高度为 wrap_content
  • 只需将Chronometer的位置更改为最后一个声明,我的意思是先写TableLayout然后Chronometer
  • 谢谢大家的建议,但我相信问题出在其他地方,因为我尝试了你所说的一切,但没有。我发布了一个新主题。stackoverflow.com/questions/24201301/…

标签: android view android-relativelayout


【解决方案1】:

您的TableLayout 占据所有空间 (match_parent) 并覆盖ChronometerRelativeLayout 子项按照声明的顺序排列。我不知道您到底想要什么,但您可以先在布局中切换两者的顺序,以便Chronometer 覆盖TableLayout

【讨论】:

  • 我应该在 TableLayout 的“layout_height”中使用什么?谢谢
【解决方案2】:

首先将Chronometer 粘贴到底部android:layout_alignParentBottom="true" 然后将TableLayout 放在Chronometer 的上方

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/firstLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableLayout
        android:id="@+id/parentLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/chrono" >
    </TableLayout>

    <Chronometer
        android:id="@+id/chrono"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Chronometer"
        android:textColor="#4169E1"
        android:textSize="20sp" />

</RelativeLayout>

【讨论】:

    【解决方案3】:

    试试这个...这绝对可以解决您的问题..

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/firstLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
    <Chronometer
        android:id="@+id/chrono"
        android:textColor="#4169E1"
        android:textSize="20sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:layout_alignParentTop="true"
        android:text="Chronometer"
    />
    
    <TableLayout 
        android:id="@+id/parentLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/chrono"
        >
    </RelativeLayout>
    

    【讨论】:

      【解决方案4】:

      我终于找到了显示计时器的方法。 感谢所有试图帮助我的人,答案非常接近我的解决方案,即:

      <Chronometer
      android:id="@+id/chrono"
      android:textColor="#4169E1"
      android:textSize="20sp"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:text="Chronometer"
      />
      <TableLayout 
      android:id="@+id/parentLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_below="@id/chrono"
      >
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-30
        • 1970-01-01
        相关资源
        最近更新 更多