android - 如何在相对布局中以父 View 为中心对齐下方的 View

标签 android android-layout android-relativelayout android-percentrelativelayout

我想在相对布局中将 centerInParent 属性设置为 true 的 View 下方对齐 Framelayout。我试过 layout_below 但它不起作用。然后我尝试删除 centerInParent 并尝试了 center_horizo​​ntal 和 center_vertical 但它也没有帮助,FrameLayout 仍然停留在布局的顶部。 这是我的布局代码:

<android.support.percent.PercentRelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="?actionBarSize"
            android:layout_marginTop="?actionBarSize"
            android:background="@android:color/transparent">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/white"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0"
                tools:src="@drawable/car_engine" />

            <View
                android:id="@+id/center_point"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:background="@color/g" />

            <View
                android:id="@+id/tab_scrim"
                android:layout_width="match_parent"
                android:layout_height="@dimen/gradiant_height"
                android:layout_alignParentBottom="true"
                android:background="@drawable/tab_scrim"
                app:layout_heightPercent="40%" />

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/center_point">

                <TextView
                    android:id="@+id/car_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingBottom="5dp"
                    android:paddingTop="2dp"
                    android:textAlignment="center"
                    android:textColor="@color/w"
                    android:textSize="20sp"
                    android:textStyle="bold"
                    tools:text="@string/car_header_text" />

                <TextView
                    android:id="@+id/car_subtitle"
                    style="@style/TitleWhite"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/car_title"
                    android:paddingBottom="4dp"
                    android:paddingTop="4dp"
                    android:text="@string/car_sub_header"
                    android:textAlignment="center" />
            </FrameLayout>
        </android.support.percent.PercentRelativeLayout>

最佳答案

将您的 PercentRelativeLayout 高度设置为 match_parent

<android.support.percent.PercentRelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="?actionBarSize"
    android:layout_marginTop="?actionBarSize"
    android:background="@android:color/transparent">

关于android - 如何在相对布局中以父 View 为中心对齐下方的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38741992/

相关文章:

android - 工具栏标题中有多种颜色?

android - ImageView adjustViewBounds 不适用于相对布局

android - 相对布局和线性布局

android - 带有 collapsingToolbarLayout、RelativeLayout 和 NestedScrollView 的自定义底部 float 按钮

java - Android 对象动画 xml

javascript - 使用 Angularjs 直接从 Controller 打开模板文件

java - 将 GLSurfaceView 类与 android xml 布局一起使用

android - 如何在android中为警报对话框设置自定义字体?

Android CursorLoader 和 LoaderManager 错误

Android - TextView 和 ImageView 的相同 OnClickListener