删除 Android 选项卡 Activity 下方的间距或填充(操作栏选项卡)

Remove Spacing or Padding below Android Tabbed Activity (Action Bar Tabs)

我刚刚创建了一个默认值 "Tabbed Activity - Action Bar Tabs (with ViewPager)" 使用 AndroidStudio

我的问题是 - 如何在滚动时删除顶部的 Spacing/Padding,但保留开头的 Spacing/Padding。

谢谢

fragment_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment">

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView android:id="@+id/section_label" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="...."></TextView>

</ScrollView>

dimens.xml

<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="0dp"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment">

我希望我正确理解了您的尝试。

只需修改XML:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="0dp"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity$PlaceholderFragment">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <View
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/activity_vertical_margin" />

        <TextView android:id="@+id/section_label" android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="...."></TextView>
    </RelativeLayout>
    </ScrollView>
</RelativeLayout>

谢谢[arpit]

想通了 刚刚添加了一些 id's

正在工作

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="0dp"
tools:context=".MainActivity$PlaceholderFragment">

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/v1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/activity_vertical_margin" />

        <TextView
            android:id="@+id/section_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/v1"
            android:text="..."></TextView>
    </RelativeLayout>
</ScrollView>

打开 res/values/dimens.xml 并更改那里的垂直边距

<dimen name="activity_vertical_margin">0dp</dimen>

如果你愿意,也可以水平:

<dimen name="activity_horizontal_margin">0dp</dimen>