34

Androidのレイアウトについての質問です。これが私が熱心に手に入れたいものです:

レイアウト

ダークグレーはLinearLayoutです。オレンジはレイアウトXで、緑はFrameLayoutです。Greenをその親の外側に配置する必要があります-レイアウトX。説明されているレイアウト階層は変更できません。唯一のオプションはレイアウトXです-それはあなたが望むものなら何でもかまいません。

何か案は?

4

3 に答える 3

73

使用する -

android:clipChildren="false"
android:clipToPadding="false"

子ビューのすべての親で、ビューの「左マージン」を負に設定します。これにより、子ビューが親ビューの外側に配置され、ビューがクリップされることもありません。

于 2015-07-13T13:01:48.347 に答える
4

緑の部分は親の外に描画できないため、レイアウト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>
于 2012-05-03T13:48:09.013 に答える
1

android:clipChildren="false"親レイアウトに追加するだけです。

<?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="horizontal"
    android:clipChildren="false">

    <LinearLayout
        android:layout_marginLeft="-25dp"
        android:background="@color/colorGray"
        android:layout_width="100dp"
        android:layout_height="100dp"/>
    <LinearLayout
        android:gravity="center|left"
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:background="@color/colorOrange">
        <LinearLayout
            android:layout_marginLeft="-25dp"
            android:background="@color/colorGreen"
            android:layout_width="50dp"
            android:layout_height="50dp"></LinearLayout>
    </LinearLayout>
</LinearLayout>
于 2019-03-29T09:05:17.200 に答える