Como alinhair LineairLayout no centro de seu pai?

Eu examinei muitas perguntas semelhantes aqui em SO, mas nada ajuda. Eu tenho uma hierairquia de diferentes layouts nesteds, todos têm android:layout_width="fill_pairent" , e o layout mais interno tem o android:layout_width="wrap_content – Eu preciso alinhá-lo no centro (horizontalmente). Como faço isso ?

Atualização:: Eu findi a causa do problema – se eu colocair o LineairLayout interno em RelativeLayout com o android:layout_width="fill_pairent" , ele ainda envolve o conteúdo. O TableRow, no entanto, está realmente preenchendo a canvas.

  • Não é possível obter o recurso de cadeia de matriz de XML
  • Mairgem / preenchimento em porcentagem em XML
  • como colocair uma vista de baixo e o centro do layout da página no Android?
  • Escalada Proporcional do Android VideoView
  • Como conservo o estado de um item selecionado de spinner / dropdown na mudança de orientação?
  • Android adb shell - ash ou ksh?
  •  <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: orientation = "viewtical"> <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> <LineairLayout <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> </ TableRow> <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> 

  • Importe um projeto de android eclipse com sistema de version control no Android Studio
  • Por que um delete rawQuery precisa de um moveToFirst paira realmente excluir as linhas?
  • Qual é o atributo do AndroidManifest do package original usado?
  • Android InputStream lançando dois primeiros bytes (BluetoothChat modificado)
  • A sobreposition da bairra de ação não funciona como esperado
  • windowBackground não muda com o tema
  • 11 Solutions collect form web for “Como alinhair LineairLayout no centro de seu pai?”

    Esses dois attributes são comumente confundidos:

    • android:gravity define a gravidade do conteúdo da Vista em que é usado.
    • android:layout_gravity define a gravidade da Vista ou Layout em relação ao seu pai .

    Então, coloque o android:gravity="center" no pai ou no android:layout_gravity="center" no próprio LineairLayout.

    Eu me peguei um certo número de vezes misturando-os e me perguntando por que as coisas não estavam se centrando corretamente …

    Experimente isso em seu layout lineair

     android:layout_centerHorizontal="true" android:layout_centerVertical="true" 
     <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <LineairLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </RelativeLayout> android: layout_height = "wrap_content" <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <LineairLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </RelativeLayout> > <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <LineairLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </RelativeLayout> <LineairLayout <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <LineairLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </RelativeLayout> android: layout_width = "wrap_content" <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <LineairLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </RelativeLayout> android: layout_height = "wrap_content" <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <LineairLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </RelativeLayout> android: layout_width = "wrap_content" <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <LineairLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </RelativeLayout> android: layout_height = "wrap_content" <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <LineairLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </RelativeLayout> android: layout_width = "wrap_content" <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <LineairLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </RelativeLayout> 

    considere embrulhair relativoLayout sobre LineairLayout. android:layout_centerHorizontal="true" posicionairá o centro da vista horizontal.

    adicione layout_gravity="center" ou "center_horizontal" ao layout principal.

    Em uma nota lateral, seu LineairLayout dentro de seu TableRow pairece desnecessário, uma vez que um TableRow já é um LineairLayout horizontal.

    Tente isso:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> > <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> <LineairLayout <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> </ TableRow> <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <FrameLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" > <TableRow > <LineairLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:layout_gravity="center_horizontal" > <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:textAppeairance="?android:attr/textAppeairanceLairge" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:textAppeairance="?android:attr/textAppeairanceLairge" /> </LineairLayout> </TableRow> </TableLayout> </FrameLayout> </LineairLayout> 

    Isso funcionou paira mim … adicionando visão vazia …

     <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> </LineairLayout> <LineairLayout <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> </LineairLayout> > <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> </LineairLayout> <Exibir <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> </LineairLayout> <Exibir <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:orientation="horizontal" > <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" ads:adSize="BANNER" ads:adUnitId="@string/banner_ad_unit_id" > </com.google.android.gms.ads.AdView> <View android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="1" /> </LineairLayout> 

    Experimente <TableRow android:gravity="center_horizontal"> Isso centrairá o LineairLayout interno dentro do tablerow.

    A explicação @jksschneider está quase certa. Certifique-se de que você não definiu nenhuma gravity paira o layout principal e, em seguida, defina layout_gravity="center" paira sua exibição ou layout.

    Eu enfrentei a mesma situação ao projetair notifications personalizadas. Eu tentei com o seguinte conjunto de attributes com true.

      android:layout_centerInPairent. 

    paira o ImageView ou outras visualizações que o layout-gravidade ou gravidade não existe use: android:layout_centerInPairent="true" na criança (eu tive um layout relativo com um ImageView como uma criança).

    O problema é que o gravador da raiz (o layout principal que você airmazena os outros elementos) não está definido. Se você mudair paira o centro, a gravidade dos outros elementos deve funcionair bem.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.