有什么方法可以将视图稍微置于其父布局之外? [英] Are there any ways to put view slightly outside its parent layout?
问题描述
这是有关Android布局的问题.这是我渴望想要得到的:
It's a question about Android layouts. Here's what I eagerly want to get:
深灰色是LinearLayout.橙色是布局X,然后绿色是FrameLayout.我需要将Green置于其父级-布局X之外.无法更改所描述的布局层次结构.唯一的选择是布局X-它可以是您想要的任何内容.
Dark-gray is a LinearLayout. Orange is layout X and then Green is a FrameLayout. I need to put Green outside its parent - layout X. The layout hierarchy described can't be changed. The only option is layout X - it could be whatever you want.
有什么想法吗?
推荐答案
您不能将Green部件放置在Layout X中,因为它不能在其父级外部绘制.
You can't put the Green part in Layout X, because it can not be drawn outside its parents.
因此,您应该实现RelativeLayout或FrameLayout(根布局)作为所有这些视图的父级.
So, you should implements a RelativeLayout or FrameLayout (root Layout) as the parents of all of these Views.
然后将绿色视图作为根布局的childView.
And Put the Green View as the childView of the root Layout.
<?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>
这篇关于有什么方法可以将视图稍微置于其父布局之外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!