2017-11-22 8 views
0

Ich habe eine schwierige Zeit versucht, meine 2 linearen Layouts zu zentrieren. Im ersten linearen Layout wird der Ländercode ausgewählt und der Text in derselben Zeile bearbeitet. Das zweite lineare Layout ist angenommen, um die Schaltfläche unter dem ersten linearen Layout zu platzieren. Aber wenn ich den Knopf unter das erste lineare Layout setze, wird es nicht mehr zentriert.Zentrieren von 2 verschiedenen Layouts in einer XML-Datei

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@color/ghostWhiteColor" 
    android:orientation="vertical" 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:padding="10dp" 
     android:gravity="center" 
     android:id="@+id/linearLayout1"> 


     <com.hbb20.CountryCodePicker 
      android:id="@+id/ccp" 
      android:layout_width="86dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      app:ccp_showFullName="false" 
      app:ccp_showNameCode="false" 
      app:ccp_showPhoneCode="true" /> 

     <com.rengwuxian.materialedittext.MaterialEditText 
      android:id="@+id/register_password" 
      android:layout_width="260dp" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="8dp" 
      android:layout_marginTop="-2dp" 
      android:hint="@string/hint_phone" 
      android:inputType="phone" 
      android:padding="10dp" 
      android:singleLine="true" 
      app:met_floatingLabel="normal" 
      app:met_helperText="Enter your phone number." 
      app:met_helperTextAlwaysShown="true" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:padding="10dp" 
     android:gravity="center"> 

     <com.rey.material.widget.Button 
      android:id="@+id/button_register_accept" 
      android:layout_width="200dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="4dp" 
      android:background="@color/holo_blue_light" 
      android:padding="10dp" 
      android:paddingEnd="50dp" 
      android:text="@string/btn_accept" 
      android:textColor="@color/ghostWhiteColor" /> 

    </LinearLayout> 

</RelativeLayout> 

Beispiel für etwas nicht zentriert. https://puu.sh/yruSe/0721745d0b.png

+0

könnten Sie setzen einen Screenshot von dem, was Sie wollen? – diegoveloper

+0

@diegoveloper Aktueller Thread eines Beispiels für etwas, das nicht zentriert ist. – user8924538

+0

ok überprüfen Sie meine Lösung unten – diegoveloper

Antwort

0

Ersetzen Sie Ihre Eltern Layout aus dieser:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@color/ghostWhiteColor" 
    android:orientation="vertical"> 

Um dies:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical"> 
0
Try this :) 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/ghostWhiteColor" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:gravity="center" 
      android:orientation="horizontal" 
      android:padding="10dp"> 


      <com.hbb20.CountryCodePicker 
       android:id="@+id/ccp" 
       android:layout_width="86dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="8dp" 
       app:ccp_showFullName="false" 
       app:ccp_showNameCode="false" 
       app:ccp_showPhoneCode="true" /> 

      <com.rengwuxian.materialedittext.MaterialEditText 
       android:id="@+id/register_password" 
       android:layout_width="260dp" 
       android:layout_height="wrap_content" 
       android:layout_marginRight="8dp" 
       android:layout_marginTop="-2dp" 
       android:hint="@string/hint_phone" 
       android:inputType="phone" 
       android:padding="10dp" 
       android:singleLine="true" 
       app:met_floatingLabel="normal" 
       app:met_helperText="Enter your phone number." 
       app:met_helperTextAlwaysShown="true" /> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/linearLayout2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:padding="10dp"> 

      <com.rey.material.widget.Button 
       android:id="@+id/button_register_accept" 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_margin="4dp" 
       android:background="@color/holo_blue_light" 
       android:padding="10dp" 
       android:text="@string/btn_accept" 
       android:textColor="@color/ghostWhiteColor" /> 

     </LinearLayout> 
    </LinearLayout> 

</RelativeLayout> 
Verwandte Themen