android - RelativeLayout高度填充CollapsingToolBarLayout的剩余空间

时间:2017-05-29 23:16:17

标签: android android-layout android-relativelayout android-collapsingtoolbarlayout

我有以下设计,其中顶部和下方有一个CollapsingToolbarLayout,有一个RelativeLayout:

enter image description here

我希望RelativeLayout将剩余的空间填充到底部,这样我就可以像这样集中内容:

enter image description here

我尝试在RelativeLayout上使用 match_parent ,但它需要整个根布局的大小,包括CollapsingToolbarLayout:

enter image description here

我该怎么办?这是完整布局的代码:

include_once('../../acp/db/db.php');
$link = mysql_connect($dbhost, $dbuser, $dbpassword, $dbname);
     mysql_select_db($dbname);
     if (!$link) {
       die('Could not connect: ' . mysql_error());
     }
if(isset($_POST['user_comm']) && isset($_POST['user_name']) && isset($_POST['user_mail']))
{
  $comment=$_POST['user_comm'];
  $name=$_POST['user_name'];
  $mail=$_POST['user_mail'];
  $post_id=$_POST['post_id'];
  $insert=mysql_query("INSERT INTO comment (name,mail,comment,post_id) VALUES ('$name', '$mail', '$comment', '$post_id')");

  $select=mysql_query("SELECT * FROM `comment`  WHERE post_id = '$id_post' ORDER BY `date` DESC");

  if($row=mysql_fetch_array($select))
  {
      $name=$row['name'];
      $comment=$row['comment'];
    $date=$row['date'];
  ?>
  <div class='media'>
        <a class='pull-left' href='#'>
            <img class='media-object' src=' <?php echo $grav_url; ?>' >
        </a>
        <div class='media-body'><?php echo $name; ?>
            <h4 class='media-heading'>
                <small><?php echo $date; ?></small>
            </h4>
              <?php echo $comment; ?>
        </div>
    </div>
  <?php
  }
exit;
}
?>

4 个答案:

答案 0 :(得分:5)

尝试使用Appbar Scroll监听器

AVAsset

答案 1 :(得分:0)

参考下面的代码:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:id="@+id/activity_user_eventsalert"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="No events yet"
            android:textColor=""
            android:textSize="20sp"/>
    </LinearLayout>

</RelativeLayout>

答案 2 :(得分:-1)

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/calendar_remove_titlegray_48px"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="No events yet"
                android:textSize="20sp"
                android:textColor="@color/colorTitleGray"/>
        </LinearLayout>

    </RelativeLayout>

答案 3 :(得分:-1)

在相对布局中添加此代码:

android:gravity="center"
android:layout_weight="1"