A view does not show inside a relative layout

后端 未结 4 1995
别那么骄傲
别那么骄傲 2021-01-29 15:05

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 s

相关标签:
4条回答
  • 2021-01-29 15:10

    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>
    
    0 讨论(0)
  • 2021-01-29 15:14

    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>
    
    0 讨论(0)
  • 2021-01-29 15:21

    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.

    0 讨论(0)
  • 2021-01-29 15:31

    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"
    >
    
    0 讨论(0)
提交回复
热议问题