Question

I want to have a Image-button and below image-button i want Text-view. I think I made everything right, but it just doesn't show up. Any ideas?

Here is the code:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#A9F5E1"
              android:orientation="vertical">
    <TableRow android:padding="5dp"
              android:paddingBottom="10dp">
        <ImageButton android:layout_height="150dp"
                  android:layout_width="400dp"
                  android:src="@drawable/flood_sign"
                  android:background="@android:color/transparent"
                  android:id="@+id/enterPreventiva"/>
        <TextView android:layout_height="wrap_content"
                  android:layout_width="fill_parent"
                  android:text="@string/preventiva"
                  android:textColor="#FFFFFF"/>
    </TableRow>
</TableLayout>
Was it helpful?

Solution

Add a new row and place it there.

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="#A9F5E1"
          android:orientation="vertical">
   <TableRow android:padding="5dp"
          android:paddingBottom="10dp">
       <ImageButton android:layout_height="150dp"
              android:layout_width="400dp"
              android:src="@drawable/flood_sign"
              android:background="@android:color/transparent"
              android:id="@+id/enterPreventiva"/>
   </TableRow>
   <TableRow android:padding="5dp"
          android:paddingBottom="10dp">
       <TextView android:layout_height="wrap_content"
              android:layout_width="fill_parent"
              android:text="@string/preventiva"
              android:textColor="#FFFFFF"/>
  </TableRow>
</TableLayout>

OTHER TIPS

you need to reduse width of your ImageButton

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="#A9F5E1"
          android:orientation="vertical">
<TableRow android:padding="5dp"
          android:paddingBottom="10dp">
    <ImageButton android:layout_height="150dp"
              android:layout_width="200dp"
              android:src="@drawable/ic_launcher"
              android:background="@android:color/transparent"
              android:id="@+id/enterPreventiva"/>
    <TextView android:layout_height="wrap_content"
              android:layout_width="fill_parent"
              android:text="pratik"
              android:textColor="#FFFFFF"/>
</TableRow>

Otherwise you can take this text in new row

You can do like this way :

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#A9F5E1"
              android:orientation="vertical">
    <TableRow android:padding="5dp"
              android:paddingBottom="10dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/enterPreventiva"
                android:layout_width="400dp"
                android:layout_height="150dp"
                android:background="@android:color/transparent"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="tes"
                android:textColor="#000000"
                android:textSize="50dp" />

        </LinearLayout>

    </TableRow>
</TableLayout>

Use a frame layout there. it will overlap text over button

<FrameLayout
        android:layout_width="wrap_content"
    android:layout_height="match_parent">
    <ImageButton android:layout_height="150dp"
                  android:layout_width="400dp"
                  android:src="@drawable/flood_sign"
                  android:background="@android:color/transparent"
                  android:id="@+id/enterPreventiva">
    </ImageButton>

    <TextView android:layout_height="wrap_content"
              android:layout_width="fill_parent"
              android:text="@string/preventiva"
              android:textColor="#FFFFFF">
    </TextView>
</FrameLayout>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top