A view does not show inside a relative layout

我们两清 提交于 2019-12-20 07:56:20

问题


I have a problem with this layout and i cannot find out what is wrong. As you can see, there is a chronometer and a table inside a relative layout but the chronometer does not show, not even a blank space.

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

any ideas?


回答1:


Your TableLayout takes over all space (match_parent) and draws over the Chronometer. RelativeLayout children are laid out in order they are declared. I don't know what you want exactly, but you can start by switching the order of the two in your layout so that the Chronometer draws over the TableLayout.




回答2:


First Stick Chronometer to bottom android:layout_alignParentBottom="true" then take TableLayout on above of 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:


Try this...this will definitly solve your problem..

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


finally i got the way to display the chronometer. Thanks to everyone who tried to help me, the answers were really close to my solution which is:

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


来源:https://stackoverflow.com/questions/24183348/a-view-does-not-show-inside-a-relative-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!