2015-06-10 1 views
-1

Моя цель - иметь форму с фоном белого цвета в центре экрана. Просто последовал за каким-то другим ответом на SO, но я не могу достичь своей цели.Плагин для Android: как расположить расположение детей в центре экрана?

Только если я удаляю белый фон, макет идет в центре. Но у меня есть изображение на фоне, поэтому мне нужно (и я хочу научиться!) Вставить белый фон, чтобы помочь пользователю.

Большое спасибо

enter image description here

Это НЕГО activity_login.xml

<?xml version="1.0" encoding="utf-8"?> 
<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:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:background="@drawable/background" 
    android:scaleType="centerCrop" 
    tools:context=".LoginActivity"> 

     <LinearLayout 
      android:background="#FFFFFF" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:gravity="center" > 


      <EditText android:id="@+id/username" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="@string/username" 
       /> 

      <EditText android:id="@+id/password" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       /> 

      <Button 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/login" 
       android:onClick="performLogin" /> 

     </LinearLayout> 

    </RelativeLayout> 

Это styles.xml

<resources> 



    <!-- Base application theme. --> 
    <style name="MyAppTheme" parent="Theme.AppCompat.Light"> 

    </style> 

</resources> 

Спасибо за вашу помощь!

ответ

2

Добавить метку android:layout_centerVertical="true" в LinearLayout в центр по вертикали.

Смежные вопросы