how to center table layout inside relative layout

user3713255

I have a table layout that contain two edit texts and a spinner in each row, I want to center it inside a relative layout but I couldn`t get around it.

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
android:id="@+id/Relative_4"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:src="@drawable/SomePhoto" />

<TableLayout 
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="40dp"
    android:clickable="false"
    android:duplicateParentState="false"
    android:focusable="false"
    android:layoutDirection="rtl"
    android:focusableInTouchMode="false"
    android:longClickable="false"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

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

    <EditText
        android:id="@+id/editText_4_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:duplicateParentState="false"
        android:ems="5"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:freezesText="false"
        android:gravity="center_vertical|center_horizontal"
        android:inputType="none"
        android:longClickable="false"
        android:scrollHorizontally="false"
        android:text="Course"
        android:textAllCaps="false" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText_4_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:duplicateParentState="false"
        android:ems="6"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="center_vertical|center_horizontal"
        android:inputType="none"
        android:longClickable="false"
        android:text="credit hours"
        android:layout_centerHorizontal="true" />

    <EditText
        android:id="@+id/editText_4_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:duplicateParentState="false"
        android:ems="4"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="center_vertical|center_horizontal"
        android:inputType="none"
        android:longClickable="false"
        android:text="Grades" />

</TableRow>

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="24.67" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >


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

    <EditText
        android:id="@+id/editText_4_4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="4"
        android:gravity="center_vertical|center_horizontal"
        android:hint="course_1"
        android:maxLines="1" />

    <EditText
        android:id="@+id/editText_4_5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="6"
        android:gravity="center_vertical|center_horizontal"
        android:inputType="number"
        android:text="0" />

    <Spinner
        android:id="@+id/spinner_4_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</TableRow>



<RelativeLayout
    android:id="@+id/tableRow13"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:baselineAligned="true" >



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

        <Button
            android:background="@drawable/ResetBtn"
            android:id="@+id/button_4_1"
            android:layout_marginLeft="70dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            /> 
        <Button
        android:background="@drawable/CalculateBtn"
        android:id="@+id/button_4_2"
        android:layout_toRightOf="@+id/button_4_1"
        android:layout_marginLeft="90dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />
    </RelativeLayout>


</RelativeLayout>
</TableLayout>
</ScrollView>

<com.mopub.mobileads.MoPubView
android:id="@+id/adview"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
/>

</TableLayout>

</RelativeLayout>

Any help on how to get around this issue would be appreciated. Thankx

Wasim Ahmed

Make these changes to you xml code..i hope it will work

 <RelativeLayout 
    android:id="@+id/Relative_4"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" //This is new line
    >

    <TableLayout 
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:layout_centerInParent="true"//This is new line      
        android:clickable="false"
        android:focusable="false"
        android:layoutDirection="rtl"
        android:focusableInTouchMode="false"
        android:longClickable="false"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to vertically and horizontally center a linear layout inside a relative layout

From Dev

how to set Linearlayout Center inside relative layout in android

From Dev

How to dynamically insert a relative layout into a table layout

From Dev

Android relative layout center

From Dev

How to center a view in parent and add a view below it inside a Relative Layout inside a Scroll view

From Java

How to center the content inside a linear layout?

From Dev

Relative Layout: How to center view in the remaining space to the right of an element?

From Dev

How can I center a GridLayout in its relative layout parent?

From Dev

How can I center a GridLayout in its relative layout parent?

From Dev

How to position center horizontal 2 elements in a row in Relative layout

From Dev

how to set each layout below another layout inside relative layout in android

From Dev

how to set each layout below another layout inside relative layout in android

From Dev

Relative Layout with a nested Linear Layout inside. How to position the Linear layout at the bottom of the screen?

From Dev

Need help on creating 4 relative layouts inside a grid layout (2x2) and put one button in the center of each relative layout

From Dev

Android - Relative layout inside ScrollView

From Dev

Relative Layout is not allowed inside Toolbar

From Dev

How to arrange two linear layouts inside a relative layout in android?

From Dev

How to implement a table layout inside a list view

From Dev

How to center Linear layout

From Dev

How center button in layout

From Dev

Android relative layout center vertical with margin

From Dev

Android relative layout center horizontally with another view

From Dev

android - list view in center of relative layout

From Dev

In Android get center of Relative Layout on API 10

From Dev

Horizontally and vertically center a ProgressBar in Relative Layout

From Dev

Android relative layout center horizontally with another view

From Dev

Align shape to center of textview on Relative layout

From Dev

How to set Relative Layout as default layout

From Dev

How to design the layout using relative layout?

Related Related

  1. 1

    How to vertically and horizontally center a linear layout inside a relative layout

  2. 2

    how to set Linearlayout Center inside relative layout in android

  3. 3

    How to dynamically insert a relative layout into a table layout

  4. 4

    Android relative layout center

  5. 5

    How to center a view in parent and add a view below it inside a Relative Layout inside a Scroll view

  6. 6

    How to center the content inside a linear layout?

  7. 7

    Relative Layout: How to center view in the remaining space to the right of an element?

  8. 8

    How can I center a GridLayout in its relative layout parent?

  9. 9

    How can I center a GridLayout in its relative layout parent?

  10. 10

    How to position center horizontal 2 elements in a row in Relative layout

  11. 11

    how to set each layout below another layout inside relative layout in android

  12. 12

    how to set each layout below another layout inside relative layout in android

  13. 13

    Relative Layout with a nested Linear Layout inside. How to position the Linear layout at the bottom of the screen?

  14. 14

    Need help on creating 4 relative layouts inside a grid layout (2x2) and put one button in the center of each relative layout

  15. 15

    Android - Relative layout inside ScrollView

  16. 16

    Relative Layout is not allowed inside Toolbar

  17. 17

    How to arrange two linear layouts inside a relative layout in android?

  18. 18

    How to implement a table layout inside a list view

  19. 19

    How to center Linear layout

  20. 20

    How center button in layout

  21. 21

    Android relative layout center vertical with margin

  22. 22

    Android relative layout center horizontally with another view

  23. 23

    android - list view in center of relative layout

  24. 24

    In Android get center of Relative Layout on API 10

  25. 25

    Horizontally and vertically center a ProgressBar in Relative Layout

  26. 26

    Android relative layout center horizontally with another view

  27. 27

    Align shape to center of textview on Relative layout

  28. 28

    How to set Relative Layout as default layout

  29. 29

    How to design the layout using relative layout?

HotTag

Archive