【问题标题】:remove margins around main layout删除主布局周围的边距
【发布时间】:2016-09-10 18:42:12
【问题描述】:

我正在尝试在 android 中制作一个选项卡小部件,它填充布局宽度并直接放置在我的活动的操作栏下方,但我的选项卡小部件周围的白色边距阻止我实现我的视图,所以任何人都可以请帮我从我的主要相对布局周围删除这些边距(在下面的图片链接中用红色标记)?

Marked white spaces

以下是我的 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:gravity="left"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.idm.ui.MainActivity" >

<TabHost
    android:id="@+id/tabHost"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:adjustViewBounds="true"
    android:layout_marginTop="-16dp" 
    android:layout_marginLeft="-15dp"
    android:layout_marginRight="-17dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" 
            android:background="#000000">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="fill_vertical|center"
                android:showDividers="none" >
            </TabWidget>

        </LinearLayout>

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

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <RelativeLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >

                    <ListView
                        android:id="@+id/elvDownloading"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
                    </ListView>
                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/tab2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical" >

                    <ListView
                        android:id="@+id/elvDownloaded"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
                    </ListView>
                </RelativeLayout>
            </FrameLayout>
        </LinearLayout>

    </LinearLayout>
</TabHost>

提前致谢

【问题讨论】:

    标签: java android eclipse


    【解决方案1】:

    您应该发布布局 XML 文件,但这些很可能是默认活动填充(在 @dimen/activity_vertical_margin@dimen/activity_horizontal_margin 中定义)。

    在您的布局 XML 文件中查找 android:padding*android:margin* 值并将它们设置为 0 或在不需要时删除它们。

    添加 XML 后编辑:

    是的,您应该删除这些行:

    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    

    【讨论】:

    • 感谢 Nohus,我尝试设置自定义填充和边距,但没有任何效果,我已经编辑了我的问题,所以请查看我的代码
    • 您是否尝试删除这 4 行?