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

前端之家收集整理的这篇文章主要介绍了android – 有没有办法把视图略微超出其父版本?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是一个有关 Android布局的问题.这是我急切想要得到的:

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

有任何想法吗?

解决方法

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

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

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

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/layout_root"
  4. android:layout_width="fill_parent"
  5. android:layout_height="200dp"
  6. android:orientation="vertical" >
  7.  
  8. <LinearLayout
  9. android:id="@+id/layout_dark_grey"
  10. android:layout_width="100dp"
  11. android:layout_height="match_parent"
  12. android:orientation="vertical" >
  13. </LinearLayout>
  14.  
  15. <LinearLayout
  16. android:id="@+id/layout_orange"
  17. android:layout_width="match_parent"
  18. android:layout_height="match_parent"
  19. android:layout_toRightOf="@id/layout_dark_grey"
  20. android:orientation="vertical" >
  21. </LinearLayout>
  22.  
  23. <RelativeLayout
  24. android:id="@+id/layout_green"
  25. android:layout_width="100dp"
  26. android:layout_height="100dp"
  27. android:layout_centerVertical="true"
  28. android:layout_toLeftOf="300dp" >
  29. </RelativeLayout>
  30.  
  31. </RelativeLayout>

猜你在找的Android相关文章