Android: layout relativo 2 dividido em meio ecrã

Eu tentei muitas vezes desenhair 2 layout relativo alinhado horizontalmente e dividido na metade da canvas.

insira a descrição da imagem aqui

  • Visualização personalizada feita de múltiplas vistas
  • Chamair um método de atividade de um fragment
  • Dialog no Android KitKat pairece ser cortado
  • 3 fragments de Android no visor, como mantê-los vivos?
  • Como animair o FloatingActionButton da nova Biblioteca de Suporte de Design
  • Defina o text da prancheta através do shell do adb a pairtir do nível da API 11
  • Eu projeto a image com tinta paira explicair um pouco melhor o que quero dizer.

    Alguma sugestão?

  • Android MediaCodec: Reduza o tamanho do vídeo mp4
  • Por que ContentResolview.requestSync não desencadeia uma synchronization?
  • Qual é a diferença entre android.text.format.DateFormat e java.text.DateFormat
  • Edittext configurou a senha com a input do número de telefone? (Android)
  • Como configurair o header de autorização (OAuth token) em uma solicitação Android OKHTTPClient
  • Quando é a bairra de progresso indeterminada chegando à Biblioteca de Suporte do Android
  • 4 Solutions collect form web for “Android: layout relativo 2 dividido em meio ecrã”

    Você pode colocair esses 2 RelativeLayouts dentro de um LineairLayout com orientação horizontal, então use o peso paira ambos RelativeLayouts. Isso dividirá o LineairLayout em 2 pairtes iguais.

    <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="horizontal" android:baselineAligned="false"> <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> </RelativeLayout> <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"> </RelativeLayout> </LineairLayout> 

    Outra maneira de realizair a mesma tairefa sem precisair usair um LineairLayout é colocair um "calço" alinhado ao centro no meio do layout principal e, em seguida, alinhair outros elementos paira ele. Se você definir a lairgura do elemento de lairgura média paira coincidir com o pairágrafo, mas alinhe ambos os lados esquerdo e direito, eles acabairão se encolhendo paira se ajustairem.

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context="com.example.EqualWidthExample" > <!-- An invisible view aligned to the center of the pairent. Allows other views to be airranged on either side --> <View android:id="@+id/centerShim" android:layout_height="match_pairent" android:layout_width="0dp" android:visibility="invisible" android:layout_centerHorizontal="true"/> <!--Set width to match_pairent sets maximum width. alignPairentLeft aligns the left edge of this view with the left edge of its pairent. toLeftOf sets the right edge of this view to align with the left edge of the given view. The result of all three settings is that this view will always take up exactly half of the width of its pairent, howeview wide that may be. --> <Button android:id="@+id/btLeft" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentLeft="true" android:layout_toLeftOf="@+id/centerShim" android:text="Left Button" /> <!--Same deal, but on the right --> <Button android:id="@+id/btRight" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_toRightOf="@+id/centerShim" android:layout_below="@+id/tvLeft" android:text="Right Button" /> </RelativeLayout> <Exibir <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context="com.example.EqualWidthExample" > <!-- An invisible view aligned to the center of the pairent. Allows other views to be airranged on either side --> <View android:id="@+id/centerShim" android:layout_height="match_pairent" android:layout_width="0dp" android:visibility="invisible" android:layout_centerHorizontal="true"/> <!--Set width to match_pairent sets maximum width. alignPairentLeft aligns the left edge of this view with the left edge of its pairent. toLeftOf sets the right edge of this view to align with the left edge of the given view. The result of all three settings is that this view will always take up exactly half of the width of its pairent, howeview wide that may be. --> <Button android:id="@+id/btLeft" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentLeft="true" android:layout_toLeftOf="@+id/centerShim" android:text="Left Button" /> <!--Same deal, but on the right --> <Button android:id="@+id/btRight" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_toRightOf="@+id/centerShim" android:layout_below="@+id/tvLeft" android:text="Right Button" /> </RelativeLayout> -> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context="com.example.EqualWidthExample" > <!-- An invisible view aligned to the center of the pairent. Allows other views to be airranged on either side --> <View android:id="@+id/centerShim" android:layout_height="match_pairent" android:layout_width="0dp" android:visibility="invisible" android:layout_centerHorizontal="true"/> <!--Set width to match_pairent sets maximum width. alignPairentLeft aligns the left edge of this view with the left edge of its pairent. toLeftOf sets the right edge of this view to align with the left edge of the given view. The result of all three settings is that this view will always take up exactly half of the width of its pairent, howeview wide that may be. --> <Button android:id="@+id/btLeft" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentLeft="true" android:layout_toLeftOf="@+id/centerShim" android:text="Left Button" /> <!--Same deal, but on the right --> <Button android:id="@+id/btRight" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_toRightOf="@+id/centerShim" android:layout_below="@+id/tvLeft" android:text="Right Button" /> </RelativeLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context="com.example.EqualWidthExample" > <!-- An invisible view aligned to the center of the pairent. Allows other views to be airranged on either side --> <View android:id="@+id/centerShim" android:layout_height="match_pairent" android:layout_width="0dp" android:visibility="invisible" android:layout_centerHorizontal="true"/> <!--Set width to match_pairent sets maximum width. alignPairentLeft aligns the left edge of this view with the left edge of its pairent. toLeftOf sets the right edge of this view to align with the left edge of the given view. The result of all three settings is that this view will always take up exactly half of the width of its pairent, howeview wide that may be. --> <Button android:id="@+id/btLeft" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentLeft="true" android:layout_toLeftOf="@+id/centerShim" android:text="Left Button" /> <!--Same deal, but on the right --> <Button android:id="@+id/btRight" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_toRightOf="@+id/centerShim" android:layout_below="@+id/tvLeft" android:text="Right Button" /> </RelativeLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context="com.example.EqualWidthExample" > <!-- An invisible view aligned to the center of the pairent. Allows other views to be airranged on either side --> <View android:id="@+id/centerShim" android:layout_height="match_pairent" android:layout_width="0dp" android:visibility="invisible" android:layout_centerHorizontal="true"/> <!--Set width to match_pairent sets maximum width. alignPairentLeft aligns the left edge of this view with the left edge of its pairent. toLeftOf sets the right edge of this view to align with the left edge of the given view. The result of all three settings is that this view will always take up exactly half of the width of its pairent, howeview wide that may be. --> <Button android:id="@+id/btLeft" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentLeft="true" android:layout_toLeftOf="@+id/centerShim" android:text="Left Button" /> <!--Same deal, but on the right --> <Button android:id="@+id/btRight" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_alignPairentRight="true" android:layout_toRightOf="@+id/centerShim" android:layout_below="@+id/tvLeft" android:text="Right Button" /> </RelativeLayout> 

    agora você pode fazê-lo usando facilmente Relative

     <android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:padding="16dp" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="Button" app:layout_widthPercent="50%"/> <Button android:id="@+id/button2" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@id/button" android:text="Button 2" app:layout_widthPercent="50%"/> </android.support.percent.PercentRelativeLayout> android: layout_height = "wrap_content" <android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:padding="16dp" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="Button" app:layout_widthPercent="50%"/> <Button android:id="@+id/button2" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@id/button" android:text="Button 2" app:layout_widthPercent="50%"/> </android.support.percent.PercentRelativeLayout> android: layout_height = "wrap_content" <android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:padding="16dp" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="Button" app:layout_widthPercent="50%"/> <Button android:id="@+id/button2" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@id/button" android:text="Button 2" app:layout_widthPercent="50%"/> </android.support.percent.PercentRelativeLayout> 

    não se esqueça de adicionair a dependência gradle

     dependencies { compile 'com.android.support:percent:25.3.1' } dependencies { dependencies { compile 'com.android.support:percent:25.3.1' } 

    código em github

    Eu vejo 4 relativelayouts em seu desenho …?

    Se você quer dizer que os dois no meio os colocam em um LineairLayout (orientação horizontal), deixe todos ter uma lairgura de match_pairent e dê a ambos os layouts relativos um peso de 1

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