android – 有没有办法把视图略微超出其父版本?

这是一个有关 Android布局的问题.这是我急切想要得到的:

深灰色是一个LinearLayout.橙色是布局X,然后绿色是FrameLayout.我需要把绿色放在父母之外 – 布局X.所描述的布局层次是不能改变的.唯一的选择是布局X – 它可以是任何你想要的.

有任何想法吗?

解决方法

您不能将绿色部分放在布局X中,因为它不能在父母之外绘制.

因此,您应该实现一个RelativeLayout或FrameLayout(根布局)作为所有这些视图的父母.

并将绿色视图作为根布局的childView.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/layout_dark_grey"
        android:layout_width="100dp"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_orange"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/layout_dark_grey"
        android:orientation="vertical" >
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/layout_green"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerVertical="true"
        android:layout_toLeftOf="300dp" >
    </RelativeLayout>

</RelativeLayout>

相关文章

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