Why is not center this layout?

pippo15

This is my layout that is an action bar that I have built:

<LinearLayout
        android:orientation="horizontal"
        android:id="@+id/Layout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/button_blue_no_border">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:orientation="horizontal">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:background="@drawable/white"
                />
            <TextView
                android:id="@+id/textActionBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:text="@string/app_name"
                android:textStyle="bold"/>
            </LinearLayout>

    </LinearLayout>

Unfortunely the image is on the left and the textview is near the image. I want that the second linear Layout is centered in the first layout. What have I to do?

A B
<RelativeLayout
        android:orientation="horizontal"
        android:id="@+id/Layout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/button_blue_no_border">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:orientation="horizontal">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:background="@drawable/white"
                />
            <TextView
                android:id="@+id/textActionBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textColor="@color/white"
                android:text="@string/app_name"
                android:textStyle="bold"/>
            </LinearLayout>

 </RelativeLayout>

Or take a look here How to align LinearLayout at the center of its parent?

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

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

編集
0

コメントを追加

0

関連記事

分類Dev

Center a widget in a layout with Qt Designer

分類Dev

CSS grid layout last item center

分類Dev

Vertically center subview using Auto-Layout

分類Dev

Align shape to center of textview on Relative layout

分類Dev

Why are the components not appearing in the center of the screen?

分類Dev

Why is this flexbox layout broken in Safari?

分類Dev

Animate auto-layout constraint constant X to the center of the parent view

分類Dev

React Native: render layout with form in center, and flex background

分類Dev

How to make a floating box in the center of the screen with responsive layout?

分類Dev

Why I can't center this form?

分類Dev

Why are my buttons/links not aligned in the center?

分類Dev

Angular Flex Layout refuses to center container horizontally, applied directives to div, router outlet, everything, yet it still wont center

分類Dev

Angular MaterialとIE: Internet Explorerでlayout-align="center center"ができない

分類Dev

layout_gravity = "center_vertical"とlayout_centerVertical = "true"の違いは何ですか

分類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

layout-align = "center"が機能しないAngular

分類Dev

layout_gravity = "center_vertical"が機能しない

分類Dev

Widget appears in the left even with attribute android:layout_gravity="center_horizontal"

分類Dev

Three column layout - middle one dynamic width, other two fill up the rest of the container and center the middle one

分類Dev

Why aren't my WPF radio buttons vertically aligned to the center?

分類Dev

Why is app icon missing for toast notifications in action center on desktop?

分類Dev

Why does firefox change align="center" to align="middle"?

分類Dev

Why do I get the layout alongwith the ajax result

分類Dev

Android/Layout - Problems to understand why button isn't at the bottom of the page

分類Dev

Why does the method referenced by the onClick layout XML need to be public?

分類Dev

Why doesn't my HTML structure work with the CSS Grid layout?

分類Dev

android:layout_centerVerticalとandroid:layout_gravity = "center_vertical"に違いはありますか?

分類Dev

Why does "position: absolute; left: 0; right: 0; width: XYpx; margin: 0 auto" actually center?

分類Dev

Why won't flexbox center my image like the other elements within the div?

Related 関連記事

  1. 1

    Center a widget in a layout with Qt Designer

  2. 2

    CSS grid layout last item center

  3. 3

    Vertically center subview using Auto-Layout

  4. 4

    Align shape to center of textview on Relative layout

  5. 5

    Why are the components not appearing in the center of the screen?

  6. 6

    Why is this flexbox layout broken in Safari?

  7. 7

    Animate auto-layout constraint constant X to the center of the parent view

  8. 8

    React Native: render layout with form in center, and flex background

  9. 9

    How to make a floating box in the center of the screen with responsive layout?

  10. 10

    Why I can't center this form?

  11. 11

    Why are my buttons/links not aligned in the center?

  12. 12

    Angular Flex Layout refuses to center container horizontally, applied directives to div, router outlet, everything, yet it still wont center

  13. 13

    Angular MaterialとIE: Internet Explorerでlayout-align="center center"ができない

  14. 14

    layout_gravity = "center_vertical"とlayout_centerVertical = "true"の違いは何ですか

  15. 15

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

  16. 16

    layout-align = "center"が機能しないAngular

  17. 17

    layout_gravity = "center_vertical"が機能しない

  18. 18

    Widget appears in the left even with attribute android:layout_gravity="center_horizontal"

  19. 19

    Three column layout - middle one dynamic width, other two fill up the rest of the container and center the middle one

  20. 20

    Why aren't my WPF radio buttons vertically aligned to the center?

  21. 21

    Why is app icon missing for toast notifications in action center on desktop?

  22. 22

    Why does firefox change align="center" to align="middle"?

  23. 23

    Why do I get the layout alongwith the ajax result

  24. 24

    Android/Layout - Problems to understand why button isn't at the bottom of the page

  25. 25

    Why does the method referenced by the onClick layout XML need to be public?

  26. 26

    Why doesn't my HTML structure work with the CSS Grid layout?

  27. 27

    android:layout_centerVerticalとandroid:layout_gravity = "center_vertical"に違いはありますか?

  28. 28

    Why does "position: absolute; left: 0; right: 0; width: XYpx; margin: 0 auto" actually center?

  29. 29

    Why won't flexbox center my image like the other elements within the div?

ホットタグ

アーカイブ