【问题标题】:Android - Remove extra space in viewpagerAndroid - 删除 viewpager 中的额外空间
【发布时间】:2015-09-05 21:49:42
【问题描述】:

我的 ViewPager 中有一个片段,但我希望它占用所有空间。现在有一些空间(我将背景设置为淡黄色),我怀疑它可能是 viewpager 添加的默认填充,但我不确定。

我尝试将 ViewPager 上的内边距设置为 -10dp,但它似乎只适用于左/右,而不是顶部/底部,并且在某些设备上根本不起作用。

我的主要布局

<?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>

【问题讨论】:

  • 使用层次视图来确定该空间的去向。

标签: android android-viewpager fragment padding


【解决方案1】:

从根RelativeLayout(合并标记之后的那个)中删除padding

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 2013-08-21
    • 2021-12-08
    • 2016-11-23
    相关资源
    最近更新 更多