android – RelativeLayout,对齐另一个视图底部的视图,但始终低于另一个视图

基于下图,我对布局问题感到很生气

该图像代表RelativeLayout.我需要将蓝色视图与黑色视图的底部对齐.但是,如果黑色视图比红色视图和蓝色视图的总和短,我需要蓝色视图低于红色视图.我希望得到这样的结果:

我尝试使用以下xml:

<RelativeLayout
    android:id="@+id/container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <View
        android:id="@+id/blackView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:align_parentTop="true"
        android:align_parentLeft="true"/>
    <View
        android:id="@+id/redView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:align_parentTop="true"
        android:align_parentRight="true"
        android:layout_toRightOf="@+id/blackView"/>
    <View
        android:id="@+id/blueView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/blackView"
        android:layout_below="@+id/redView"
        android:layout_alignParentRight="true"/>
</RelativeLayout>

但似乎layout_alignBottom的优先级高于layout_below.
我还尝试将blueView设置为与其父级的底部对齐,但结果是父级(具有wrap_content高度)变为高级作为其自己的父级(整个屏幕高度).

有没有人有同样的问题?

解决方法

用这个.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <View
        android:id="@+id/blackView"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        android:background="#000000" />

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.5" >

        <View
            android:id="@+id/redView"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignParentTop="true"
            android:background="#FF0000" />

        <View
            android:id="@+id/blueView"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignParentBottom="true"
            android:background="#003CFF" />
    </RelativeLayout>
</LinearLayout>

</LinearLayout>

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...