Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show TextView always on top

Tags:

java

android

view

In my app, I´ve got 20 buttons that cover the whole display. Always one of them is visible and every second another one is shown. This should be a little game.

Now, I need to add a score TextView so that the user knows, how much points he has at the moment. What is the best way to realize that? Like I said, the whole display is covered with the 20 buttons.

Here´s the first Row of my TableLayout:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" 


    android:background="@drawable/bg">


    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/te"
        />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="70dp"


        android:background="@drawable/te"
         />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    android:layout_marginLeft="140dp"
        android:background="@drawable/te"
/>

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    android:layout_marginLeft="210dp"

        android:background="@drawable/te"
         />


    </TableRow>
like image 319
user896692 Avatar asked Oct 14 '25 08:10

user896692


2 Answers

Alternatively you have ralative layout as a parent and wrap childs into relative layout..

Now you can dynamically bring child to front in layouts by the method

your_relative_layout.bringChildToFront(your_text_view);`
like image 178
NullPointerException Avatar answered Oct 16 '25 21:10

NullPointerException


Use FrameLayout to set TextView over your buttons or RelativeLayout.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

   <LinearLayout ...>
   // YOUR LAYOUT WITH BUTTONS 
   </LinearLayout>

   <TextView
   android:text="TEXT OVER BUTTONS"
   android:layout_height="wrap_content"
   android:layout_width="wrap_content"
   android:gravity="center"/>
</FrameLayout>
like image 24
michal.luszczuk Avatar answered Oct 16 '25 21:10

michal.luszczuk