2015-09-05 85 views
0

我的ViewPager中有一個片段,但我希望它佔用所有空間。現在有一些空間(我將背景設置爲淡黃色),我猜想它可能是viewpager添加的默認填充,但我不確定。Android - 刪除viewpager中的額外空間

我試圖將ViewPager上的填充設置爲-10dp,但它只能在左/右,而不是頂/底上工作,並且在某些設備上完全不起作用。

I want to remove all yellow space

我主要佈局

<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto"> 
    <RelativeLayout 
     android:id="@+id/appointment_gallery_toolbar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:layout_alignParentBottom="true" 
     android:background="#22000000" 
     android:padding="5dp" 
     > 
     <TextView 
      style="@style/TextViewDark" 
      android:id="@+id/appointment_gallery_imagecount" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
     /> 
     <ImageView 
      android:id="@+id/appointment_gallery_zoomout" 
      android:background="@drawable/zoom_out" 
      android:contentDescription="@string/appointment_gallery_zoomout" 
      android:layout_toLeftOf="@+id/appointment_gallery_delete" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_marginLeft="10dp" 
      /> 
     <ImageView 
      android:id="@+id/appointment_gallery_add" 
      android:background="@drawable/camera_add_hl" 
      android:contentDescription="@string/appointment_gallery_add" 
      android:layout_alignParentRight="true" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_marginLeft="10dp" 
      /> 
     <ImageView 
      android:id="@+id/appointment_gallery_add_existing" 
      android:background="@drawable/gallery_add_hl" 
      android:contentDescription="@string/appointment_gallery_add_existing" 
      android:layout_toLeftOf="@+id/appointment_gallery_add" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_marginLeft="10dp" 
      /> 
     <ImageView 
      android:id="@+id/appointment_gallery_comment" 
      android:background="@drawable/comment_add_hl" 
      android:contentDescription="@string/appointment_gallery_comment" 
      android:layout_toLeftOf="@+id/appointment_gallery_add_existing" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_marginLeft="10dp" 
      /> 
     <ImageView 
      android:id="@+id/appointment_gallery_delete" 
      android:background="@drawable/remove_hl" 
      android:contentDescription="@string/appointment_gallery_delete" 
      android:layout_toLeftOf="@+id/appointment_gallery_comment" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_marginLeft="10dp" 
      /> 
    </RelativeLayout> 
    <FrameLayout 
     android:id="@+id/appointment_gallery_comment_layout" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_above="@id/appointment_gallery_toolbar" 
     > 
     <TextView 
      style="@style/TextView" 
      android:id="@+id/appointment_gallery_comment_display" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:textColor="@color/colorPrimaryText" 
      android:ellipsize="end" 
      android:text="" 
      /> 
    </FrameLayout> 
    <android.support.v4.view.ViewPager 
     android:id="@+id/appointment_gallery_imageholder" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/app_bar" 
     android:layout_above="@id/appointment_gallery_comment_layout" 
     android:background="@color/colorAccent" 
     > 
    </android.support.v4.view.ViewPager> 
</merge> 

我的片段佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/background" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    > 
    <ImageView 
     android:id="@+id/iv" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitCenter" 
     /> 
</RelativeLayout> 
+0

使用層次結構視圖來確定空間的去向。 – CommonsWare

回答

1

從根RelativeLayout(一合併標籤後)

<RelativeLayout 
     android:id="@+id/appointment_gallery_toolbar" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:layout_alignParentBottom="true" 
     android:background="#22000000" 
     > 
刪除 padding
+0

我剛試過,但它不工作:( – pjwin

相關問題