2017-01-12 82 views
0

我正在Android中創建用戶個人資料屏幕。在此屏幕上有用戶個人資料牆紙和用戶個人資料圖片這裏的灰色背景是配置文件壁紙和紅色背景將要剖析圖像。我需要設置紅色BG佈局灰BG佈局的水平和垂直中心..父級佈局的水平和垂直中心

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/rlActivityNotificationsAndProfile"> 
<include layout="@layout/layout_tool_bar"/> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/profile_wallpaper_container_height" 
    android:id="@+id/rlProfileWallpaper" 
    android:layout_below="@+id/toolbar"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:background="#646464" 
     android:orientation="vertical" 
     android:layout_height="@dimen/profile_wallpaper_height"> 
     <LinearLayout 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:background="#A52525"> 
     </LinearLayout> 
</LinearLayout> 
<android.support.design.widget.FloatingActionButton xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/tools" 
     android:id="@+id/fabEditProfile" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="@dimen/base_ten_dp" 
     android:layout_marginEnd="@dimen/base_ten_dp" 
     android:layout_marginStart="@dimen/base_ten_dp" 
     android:scaleType="center" 
     android:src="@drawable/add" 
     app:elevation="@dimen/priority_1_elevation" 
     app:fabSize="1"/> 
</RelativeLayout> 
</LinearLayout> 
+1

使用'安卓重力=「中心」爲''父母代替LinearLayout'如果 –

+0

OP確認謝謝@RomanKolomenskii –

+0

@RomanKolomenskii您的解決方案(是嗎?),請從您的評論使OP作出答覆可以標記爲已完成。 –

回答

1

只需將你的父母的LinearLayout的重力中心(只需添加1號線):

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/rlActivityNotificationsAndProfile"> 
<include layout="@layout/layout_tool_bar"/> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/profile_wallpaper_container_height" 
    android:id="@+id/rlProfileWallpaper" 
    android:layout_below="@+id/toolbar"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:background="#646464" 
     android:orientation="vertical" 
     android:layout_height="@dimen/profile_wallpaper_height" 
     android:gravity="center"> 
     <LinearLayout 
      android:layout_width="30dp" 
      android:layout_height="30dp" 
      android:layout_gravity="center" 
      android:background="#A52525"> 
     </LinearLayout> 
</LinearLayout> 
<android.support.design.widget.FloatingActionButton xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/tools" 
     android:id="@+id/fabEditProfile" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="@dimen/base_ten_dp" 
     android:layout_marginEnd="@dimen/base_ten_dp" 
     android:layout_marginStart="@dimen/base_ten_dp" 
     android:scaleType="center" 
     android:src="@drawable/add" 
     app:elevation="@dimen/priority_1_elevation" 
     app:fabSize="1"/> 
</RelativeLayout> 
</LinearLayout> 
+0

謝謝..它的工作... –