【问题标题】:Overlay an element of view覆盖视图元素
【发布时间】:2015-08-26 13:00:04
【问题描述】:

我有一个片段的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <include layout="@layout/header" />
    </FrameLayout>

    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none" >
    </ListView>
</LinearLayout>
</FrameLayout>

这是标题:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

    <Button 
         android:id="@+id/button"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"/>

    <LinearLayout
    android:id="@+id/box"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:visibility="gone" />

</LinearLayout >

现在,当按下按钮时,“框”应该被填充并变得可见,并且框覆盖了其余的视图(在我的例子中是列表视图)。现在,当我按下按钮时,ox 不会覆盖 listview,而是占据屏幕的一部分(并且 listview 会向下移动)。 我能怎么做?谢谢

【问题讨论】:

    标签: android listview android-framelayout


    【解决方案1】:

    只需使用RelativeLayout 而不是LinearLayout,并将FrameLayout 放在xml 中ListView 之后(将标题放在列表上方):

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ListView
            android:id="@+id/listview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none" >
        </ListView>
    
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
    
            <include layout="@layout/header" />
        </FrameLayout>
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多