Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering Textview Below a image button that is under relative layout?

I have this problem of the textview is not centering below the image button. anyway to fix this issue? the coding and image is given below thx!

enter image description here

   <LinearLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp"> 

       <RelativeLayout  android:gravity="center"  android:layout_weight="1"  android:layout_width="wrap_content" android:layout_height="wrap_content"> 

  <ImageButton
      android:id="@+id/imageButton1"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:background="@null"
      android:onClick="btnCat1"
      android:src="@drawable/nopic" >
</ImageButton>

<TextView
    style="@style/MenuStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageButton1"
    android:layout_centerInParent="true"
    android:clickable="false"
    android:text="text" />

</RelativeLayout>

       <RelativeLayout  android:gravity="center"  android:layout_weight="1"  android:layout_width="wrap_content" android:layout_height="wrap_content"> 

  <ImageButton
      android:id="@+id/imageButton1"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:background="@null"
      android:onClick="btnContact"
      android:src="@drawable/nopic" >
</ImageButton>

<TextView
    style="@style/MenuStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageButton1"
    android:layout_centerInParent="true"
    android:clickable="false"
    android:text="text" />

</RelativeLayout>
</LinearLayout>






   <LinearLayout android:gravity="center_vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp"> 

       <RelativeLayout  android:gravity="center"  android:layout_weight="1"  android:layout_width="wrap_content" android:layout_height="wrap_content"> 

  <ImageButton
      android:id="@+id/imageButton1"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:background="@null"
      android:onClick="btnRoute"
      android:src="@drawable/nopic" >
</ImageButton>

<TextView
    style="@style/MenuStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageButton1"
    android:layout_centerInParent="true"
    android:clickable="false"
    android:text="text" />

</RelativeLayout>

       <RelativeLayout  android:gravity="center"  android:layout_weight="1"  android:layout_width="wrap_content" android:layout_height="wrap_content"> 

  <ImageButton
      android:id="@+id/imageButton1"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:background="@null"
      android:onClick="btnChecList"
      android:src="@drawable/nopic" >
</ImageButton>

<TextView
    style="@style/MenuStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/imageButton1"
    android:layout_centerInParent="true"
    android:clickable="false"
    android:text="text" />

</RelativeLayout>
</LinearLayout>




</LinearLayout>
like image 791
ericlee Avatar asked Jul 13 '12 07:07

ericlee


People also ask

How do I center a button in relative layout?

If you have a single Button in your Activity and you want to center it the simplest way is to use a RelativeLayout and set the android:layout_centerInParent=”true” property on the Button.

How do I center a TextView in relative layout?

android:layout_centerHorizontal="true" android:gravity="center" I think it's correct. so that TextView will be centered in Layout, and text will be centered in TextView.

How do I move TextView Center?

android:gravity="center" for text center in TextView. android:gravity="center_horizontal" inner text if you want horizontally centered. android:gravity="center_vertical" inner text if you want vertically centered. android:layout_centerInParent="true" if you want TextView in center position of parent view.


1 Answers

Try this snippet :

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

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:gravity="center_vertical" >

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@null"
            android:onClick="btnCat1"
            android:src="@drawable/ic_launcher" >
        </ImageButton>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageButton1"
            android:layout_centerInParent="true"
            android:clickable="false"
            android:text="text" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@null"
            android:onClick="btnCat1"
            android:src="@drawable/ic_launcher" >
        </ImageButton>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageButton1"
            android:layout_centerInParent="true"
            android:clickable="false"
            android:text="text" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@null"
            android:onClick="btnCat1"
            android:src="@drawable/ic_launcher" >
        </ImageButton>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageButton1"
            android:layout_centerInParent="true"
            android:clickable="false"
            android:text="text" />
    </RelativeLayout>
</LinearLayout>

enter image description here

like image 124
Venky Avatar answered Sep 22 '22 23:09

Venky