2014-09-17 5 views
0

Как я могу выровнять LinearLayout «LoginBox» со своим родителем (это RelativeLayout) как слева, так и справа? Я попытался вставить:Выровнять LinearLayout внутри проблемы RelativeLayout

android:layout_alignParentBottom="true" 
android:layout_alignParentLeft="true" 
android:layout_alignParentRight="true" 

но это не делает трюк! Infact linearlayout не правильно выровнен с краем экрана! :(

Это мой XML-код:

<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" 
    android:background="@drawable/sfondologin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="200dp" 
      android:layout_height="200dp" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:src="@drawable/stemmatrasparente" /> 

<LinearLayout 
    android:id="@+id/LoginBox" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <EditText 
      android:id="@+id/usernametxt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:background="@drawable/sfondobuttonedittext" 
      android:drawableLeft="@drawable/usericon" 
      android:ems="10" 
      android:gravity="center_horizontal|center" 
      android:paddingLeft="15dp" 
      android:imeOptions="actionNext" 
      android:singleLine="true" 
      android:textSize="18dp" 
      android:typeface="sans" > 

      <requestFocus /> 
     </EditText> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.18" > 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" > 

     <EditText 
      android:id="@+id/passwordtxt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:background="@drawable/sfondobuttonedittext" 
      android:drawableLeft="@drawable/lockicon" 
      android:ems="10" 
      android:gravity="center_vertical|center" 
      android:inputType="textPassword" 
      android:paddingLeft="15dp" 
      android:imeOptions="actionDone" 
      android:textSize="18dp" 
      android:typeface="sans" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.29" > 

     <TextView 
      android:id="@+id/forgotpass" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:text="Dimenticato la password?" 
      android:textColor="@color/white" 
      android:textColorHint="@color/white" 
      android:textSize="@dimen/value12dp" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/loginbtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:background="@drawable/sfondobuttonlogin" 
      android:text="Login" 
      android:textColor="@color/white" /> 

    </RelativeLayout> 

    <Button 
     android:id="@+id/registerbtn" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|center|end" 
     android:background="@drawable/sfondobuttonrb2" 
     android:text="Registrati" 
     android:textColor="@color/white" /> 

</LinearLayout> 
<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_gravity="left" 
    android:layout_weight="0.01" 
    android:background="#00000000"> 
</RelativeLayout> 

</RelativeLayout> 

Спасибо заранее

EDIT: Первый экран то, что я есть сейчас, пока второй, отредактированы фотошопе (извините) , является то, что я хочу, чтобы получить

Layout to edit Layout edited

+1

Я не уверен, чего вы пытаетесь достичь - пытаетесь ли вы сделать макет заполнить родителя или пытаетесь его центрировать? выравнивание влево и вправо не будет работать, потому что вы пытаетесь вытащить начало и заканчиваться в разных направлениях. –

+0

попробуйте использовать Linear Layout как родительский, а затем Make child for Relative –

ответ

1

Удалить

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 

эти линии образуют свой самый наружный ReletiveLayout. Thats it!

+0

Отлично! Вы экономите свое время :) – Peppegiuseppe

1

Попробуйте это:

<LinearLayout 
     android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="bottom"> 

<Button 
     android:id="@+id/registerbtn" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|center|end" 
     android:background="@drawable/sfondobuttonrb2" 
     android:text="Registrati" 
     android:textColor="@color/white" /> 
</LinearLayout> 

Я поставил LinearLayout до кнопки, и добавил андроид: плотность = «дно» в LinearLayout. Это должно сделать это.

+0

Смотрите мое редактирование! Я добавляю два экрана – Peppegiuseppe

+0

См. Мой отредактированный ответ – dogger20011

1

Удалить право вашего верхнего компоновщика, левый и нижние отступы:

<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" 
    android:background="@drawable/sfondologin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 
Смежные вопросы