How to group elements in xml layout for align in Android

Nut Fergie

I have TextView and ImageButton in xml layout. And ImageButton is positioned right of TextView and I want group both to center them horizontally at screen. I use RelativeLayout.

What should I do?

Sam

I assume you are developing an android application... If so this code can be used:

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

   <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerInParent="true"
       android:layout_centerHorizontal="true"
       android:orientation="horizontal">

       <TextView
           android:id="@+id/headerText"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@string/hello_world"
           />

       <ImageButton
           android:layout_width="50dp"
           android:layout_height="50dp"
           android:layout_centerHorizontal="true"
           android:layout_centerVertical="true"
           android:src="@drawable/ic_launcher" />
       </LinearLayout>


</RelativeLayout>

android:layout_centerInParent="true" will place items in the middle of the RelativeLayout parent android:layout_centerHorizontal="true" will only center items horizontally. You can remove the one you don't need.

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 group elements in xml layout for align in Android

From Dev

In XML how to align two elements (or widgets) to the right w/ Relative Layout?

From Dev

How to align the texts in a layout in android

From Dev

How to align the texts in a layout in android

From Dev

How to align gridView using XML and Layout?

From Dev

How to align the curved images in a xml layout?Is it possible to align programmatically in java?

From Dev

How to align imageView in centerVertical in Relative Layout Android

From Dev

Unable to align text to right of imageview android layout xml

From Dev

How can I align and resize these two elements with Storyboard Auto Layout?

From Dev

How to align different elements vertically in android studio?

From Dev

Layout align in android

From Dev

Android align layout center

From Dev

Android align layout center

From Dev

How we can align one or more textviews one below to another in table row of table layout in android through java code not xml

From Dev

Layout in Xml using Relative Layout not align

From Dev

How to group XML elements by node value in XSLT?

From Dev

How to properly update layout with moveable elements in Android?

From Dev

How to align buttons in android layout to make a tabbar in a mobile website?

From Dev

How to align items justified in android linear layout horizontal orientation?

From Dev

How do I align a button with the bottom of an EditText in an Android layout?

From Dev

Center align TextView in android layout

From Dev

Android: How to add on/off indicator in xml layout

From Dev

How to attach an animation to an object in layout XML in Android?

From Dev

How to read the XML from an Android layout file

From Dev

How to align div elements?

From Dev

How to align the elements in the navbar?

From Dev

How to align these elements to the center?

From Dev

android how to align radio-buttons inside radio group?

From Dev

Group XML elements by key

Related Related

  1. 1

    How to group elements in xml layout for align in Android

  2. 2

    In XML how to align two elements (or widgets) to the right w/ Relative Layout?

  3. 3

    How to align the texts in a layout in android

  4. 4

    How to align the texts in a layout in android

  5. 5

    How to align gridView using XML and Layout?

  6. 6

    How to align the curved images in a xml layout?Is it possible to align programmatically in java?

  7. 7

    How to align imageView in centerVertical in Relative Layout Android

  8. 8

    Unable to align text to right of imageview android layout xml

  9. 9

    How can I align and resize these two elements with Storyboard Auto Layout?

  10. 10

    How to align different elements vertically in android studio?

  11. 11

    Layout align in android

  12. 12

    Android align layout center

  13. 13

    Android align layout center

  14. 14

    How we can align one or more textviews one below to another in table row of table layout in android through java code not xml

  15. 15

    Layout in Xml using Relative Layout not align

  16. 16

    How to group XML elements by node value in XSLT?

  17. 17

    How to properly update layout with moveable elements in Android?

  18. 18

    How to align buttons in android layout to make a tabbar in a mobile website?

  19. 19

    How to align items justified in android linear layout horizontal orientation?

  20. 20

    How do I align a button with the bottom of an EditText in an Android layout?

  21. 21

    Center align TextView in android layout

  22. 22

    Android: How to add on/off indicator in xml layout

  23. 23

    How to attach an animation to an object in layout XML in Android?

  24. 24

    How to read the XML from an Android layout file

  25. 25

    How to align div elements?

  26. 26

    How to align the elements in the navbar?

  27. 27

    How to align these elements to the center?

  28. 28

    android how to align radio-buttons inside radio group?

  29. 29

    Group XML elements by key

HotTag

Archive