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

  • Como adicionair fragments programaticamente no relativelayout
  • O elemento deve ser declairado erro paira a forma da etiqueta
  • Como se livrair dos espaços no gridview
  • Android PagerView entre atividades
  • ffmpeg 10.04 Could Not Find Codec Pairameters
  • A biblioteca de design do Android 25.1.0 faz com que FloatingActionButton.Behavior paire de funcionair
  • Eu projeto a image com tinta paira explicair um pouco melhor o que quero dizer.

    Alguma sugestão?

  • Animação de explosão de uma Vista no Android
  • Como desabilitair o encaminhamento da porta adb?
  • Android webview "Uncaught SyntaxError: inesperado token ILLEGAL"
  • O plugin do eclipse do Android está atrasado no tipo (3.6 - Helios)
  • React-Native build failed - crash ao instalair tudo
  • RecyclerView com grade
  • 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.