2017-06-06 136 views
0

我想创建一个黑色视图并将其放在另一个视图的顶部,如下图所示。到现在为止还挺好。将一个布局放置在屏幕底部的另一个布局上

但我不知道如何将黑色视图放置在屏幕底部? (仍然在白色背景PDF格式的顶部...)

enter image description here

这是到目前为止我的XML代码:

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/background_pdf" 
     android:layout_below="@+id/background_pdf2" 
     android:orientation="vertical" 

     > 
    <com.radaee.pdf.MLPDFViewer 
     android:id="@+id/pdf" 
     android:background="@android:color/white" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:visibility="visible" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/background_pdf2" 
     android:orientation="vertical" 
     android:gravity="bottom" 
     android:layout_gravity="bottom" 
     > 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="75px" 
      android:gravity="bottom" 
      android:layout_gravity="bottom" 
      android:background="@android:color/black" 
      /> 

    </LinearLayout> 

</RelativeLayout> 

如果我下面的代码添加到android:layout_alignParentBottom="true"android:id="@+id/background_pdf2"结果是以下:

enter image description here

正如你可以看到黑色的观点被放置在机器人汤姆,但主视图(白色pdf)消失。我不明白这一点...

回答

1

android:layout_alignParentBottom="true"到您的线性布局ID background_pdf2,像下面

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

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

     <com.radaee.pdf.MLPDFViewer 
      android:id="@+id/pdf" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/white" 
      android:visibility="visible"/> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/background_pdf2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_gravity="bottom" 
     android:gravity="bottom" 
     android:orientation="vertical"> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="75px" 
      android:layout_gravity="bottom" 
      android:background="@android:color/black" 
      android:gravity="bottom" 
      /> 

    </LinearLayout> 

</RelativeLayout> 
+0

检查我的编辑答案。 Thx – user1293618

+0

请在线性布局“background_pdf”中移除android:layout_below =“@ + id/background_pdf2” –

相关问题