Android 相对于父布局的水平和垂直中心
我正在Android中创建一个用户配置文件屏幕。在此屏幕中有用户配置文件墙纸和用户配置文件图像。这里的灰色背景是配置文件墙纸,红色背景是配置文件图像。我需要将红色背景布局设置为灰色背景布局的水平和垂直中心Android 相对于父布局的水平和垂直中心,android,android-layout,Android,Android Layout,我正在Android中创建一个用户配置文件屏幕。在此屏幕中有用户配置文件墙纸和用户配置文件图像。这里的灰色背景是配置文件墙纸,红色背景是配置文件图像。我需要将红色背景布局设置为灰色背景布局的水平和垂直中心 您只需将父直线布局的重心设置为中心(只需添加一条直线): 使用android:gravity=“center”代替家长LinearLayout谢谢@RomanKolomenskii@RomanKolomenskii如果OP确认了您的解决方案(他确认了吗?),请根据您的评论回答,以便OP可以
您只需将父直线布局的重心设置为中心(只需添加一条直线):
使用android:gravity=“center”代替家长LinearLayout
谢谢@RomanKolomenskii@RomanKolomenskii如果OP确认了您的解决方案(他确认了吗?),请根据您的评论回答,以便OP可以将其标记为已完成。@Andrearonagnoli他已经确认了,np:)太棒了!我有一段时间没有加载页面,是我的错。
<?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>
<?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>