【问题标题】:Android make layouts overlap each otherAndroid使布局相互重叠
【发布时间】:2015-11-29 20:27:00
【问题描述】:

我目前有这个布局。

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

<LinearLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:background="?attr/colorPrimary">
</LinearLayout>

<LinearLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1.5"
    android:background="#E5E8EC"></LinearLayout>

但我希望在蓝色标题上重叠另一个布局,类似于此。如您所见,白色框与标题重叠。

虽然我不知道该怎么做。

【问题讨论】:

标签: android


【解决方案1】:

请检查:

<FrameLayout android:background="@color/gray">
   <View android:background="@color/purple" android:height="@dimen/header_height/>

   <LinearLayout android:orientation="vertical">
       <LinearLayout> content with user icon stats/progress </LinearLayout>
       <LinearLayout> content with white card <LinearLayout>
   </LinearLayout>    
</FrameLayout>

因此,紫色视图位于具有特定高度的所有内容下方,而在此紫色标题上方则是您想要的所有内容。

【讨论】:

  • 你所说的“经过测试”是什么意思?
  • 复制时出现很多错误,似乎不起作用。
  • 但这只是一个概念......我以为你是在询问布局使用的概念性事物以及如何适当地打包它们
  • 对不起,我的错误是混淆了。我正在寻找更具体的解决方案。
【解决方案2】:
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:background="@color/purple" />

    <!-- The photo & namename  -->
    <RelativeLayout
        android:id="@+id/foo"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        ...> 
    </RelativeLayout>

    <!-- card -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/doo"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:padding="8dp">

        ...

    </RelativeLayout>


</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多