【问题标题】:Linearlayout not taking place over fragment线性布局没有发生在片段上
【发布时间】:2017-04-15 03:31:17
【问题描述】:

我有这个布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="ca.usherbrooke.whapl.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:elevation="4dp"/>

</android.support.design.widget.AppBarLayout>


<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:orientation="horizontal"
        android:paddingTop="5dp"
        android:paddingBottom="10dp"
        android:background="@color/colorPrimary"
        >

        <ImageView
            android:id="@+id/previous"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_action_previous"/>

        <ImageView
            android:id="@+id/play_pause"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_action_play"/>

        <ImageView
            android:id="@+id/next"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ic_action_next"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:orientation="horizontal"
        android:paddingBottom="10dp"
        android:background="@color/colorPrimary"
        >

        <TextView
            android:layout_marginLeft="10dp"
            android:id="@+id/songname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            />
    </LinearLayout>

</LinearLayout>

当我的fragment_container 中有一个 ListView 时,带有播放/暂停/下一个/倒带按钮的播放器总是在容器上方,所以我无法访问列表视图中的最后一个元素,因为它在我的播放器后面( fragment_container 之后的线性布局)。

我应该为容器更改哪些内容,只占用他拥有的位置,而不是放在我的播放器下方?

顺便说一下,这个布局包含在我的主要活动的布局中,这是一个包含我的容器 + NavigationView 的 DrawerLayout。

【问题讨论】:

  • 考虑使用 LinearLayout 或 RelativeLayout 对其进行变形以使其正常工作。创建 Linearlayout 并将您的 appbarlayout 和 framelayout 放入其中。

标签: android layout fragment android-linearlayout android-coordinatorlayout


【解决方案1】:

android:layout_marginBottom 属性添加到容器中,等于播放器的高度。

【讨论】:

  • 我终于做到了,但播放器可以有不同的大小,具体取决于歌曲的名称(长标题将使用 2 行)
  • 所以尝试以编程方式获取播放器的高度,并在更改时调整容器的bottomMargin属性。或者,您可以为播放器使用 Design Support LIbrary 中的可扩展 BottomSheetBehavior。
  • 谢谢,看看BottomSheetBehavior,听起来不错!
猜你喜欢
  • 1970-01-01
  • 2017-01-11
  • 2013-12-28
  • 1970-01-01
  • 1970-01-01
  • 2013-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多