Aligning center relative to others views

Ankita

I am using only one root layout in my layout file and i cant add any nested layouts. How can I align all my views in center in all screens? For 480x800 the layout is perfect but if i change the emulator, everything is messed up.

ataulm

If you want elements within a viewgroup centered, you should use the gravity property on that viewgroup.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:gravity="center"
    >

    <TextView
        android:id="@+id/tb1"
        android:text="tb1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        />

    <TextView
        android:id="@+id/tb2"
        android:text="tb2"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        />

    <TextView
        android:id="@+id/tb3"
        android:text="tb3"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        />
</LinearLayout>

The android:gravity property defines how to align child elements, or the contents of the view.

android:layout_gravity on the other hand defines rules which are passed to the parent, instructing the parent how to align this element.

A deeper explanation: http://thinkandroid.wordpress.com/2010/01/14/how-to-position-views-properly-in-layouts/

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Aligning logo to center with Material-UI

分類Dev

ID not aligning center CSS [outlook.com]

分類Dev

Alignment of views in relative layout android

分類Dev

Relative Layout squishing child views

分類Dev

Jasper Report : Aligning text as center in text field using HTML markup

分類Dev

Set Item Alpha relative to center on Horizontal RecyclerView

分類Dev

Divs of Unequal Sizes are Unable to Center Relative to Top

分類Dev

Align shape to center of textview on Relative layout

分類Dev

When to use position absolute vs position relative when vertically aligning with css

分類Dev

iOS autolayout to center my view between two views

分類Dev

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

分類Dev

How to set multiple scroll views size to change dynamically relative to each other?

分類Dev

How do distribute n points inside a circle according to given "relative probability" for each of having a certain distance from a circle center?

分類Dev

HTMLdiv-aligning

分類Dev

Aligning TextView in CardView

分類Dev

Aligning columns in CSS Grid

分類Dev

Aligning ggplot labels

分類Dev

Aligning text into three columns

分類Dev

text aligning by dxf groups

分類Dev

Ionic contents are not aligning properly

分類Dev

Issues with Vertical Aligning in CSS

分類Dev

aligning rotated buttons easily

分類Dev

Top aligning something with Css

分類Dev

Bootstrap input is not aligning properly

分類Dev

Aligning Menu Text Horizontally

分類Dev

Print CSS Aligning Tables

分類Dev

horizontally aligning multiple divs (CSS)

分類Dev

Aligning/styling checkboxes with rest of form

分類Dev

aligning elements in their containers and the containers on the line

Related 関連記事

  1. 1

    Aligning logo to center with Material-UI

  2. 2

    ID not aligning center CSS [outlook.com]

  3. 3

    Alignment of views in relative layout android

  4. 4

    Relative Layout squishing child views

  5. 5

    Jasper Report : Aligning text as center in text field using HTML markup

  6. 6

    Set Item Alpha relative to center on Horizontal RecyclerView

  7. 7

    Divs of Unequal Sizes are Unable to Center Relative to Top

  8. 8

    Align shape to center of textview on Relative layout

  9. 9

    When to use position absolute vs position relative when vertically aligning with css

  10. 10

    iOS autolayout to center my view between two views

  11. 11

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

  12. 12

    How to set multiple scroll views size to change dynamically relative to each other?

  13. 13

    How do distribute n points inside a circle according to given "relative probability" for each of having a certain distance from a circle center?

  14. 14

    HTMLdiv-aligning

  15. 15

    Aligning TextView in CardView

  16. 16

    Aligning columns in CSS Grid

  17. 17

    Aligning ggplot labels

  18. 18

    Aligning text into three columns

  19. 19

    text aligning by dxf groups

  20. 20

    Ionic contents are not aligning properly

  21. 21

    Issues with Vertical Aligning in CSS

  22. 22

    aligning rotated buttons easily

  23. 23

    Top aligning something with Css

  24. 24

    Bootstrap input is not aligning properly

  25. 25

    Aligning Menu Text Horizontally

  26. 26

    Print CSS Aligning Tables

  27. 27

    horizontally aligning multiple divs (CSS)

  28. 28

    Aligning/styling checkboxes with rest of form

  29. 29

    aligning elements in their containers and the containers on the line

ホットタグ

アーカイブ