java - Android 应用程序 - 删除多余的填充

标签 java android

我在删除默认设置的额外填充时遇到问题。我对Java不太熟悉,但我已将线性布局的边距填充设置为0dp (垂直)并且按钮仍然没有覆盖整个页面。

To be more clear, I want the buttons to cover the entire front page. None of the gray area to be visible.

视觉:

enter image description here

Styles.xml

resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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="@dimen/activity_vertical_margin"
    tools:context="com.example.it5.foothillers.MainActivity"
    android:background="#f4f4f4">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:weightSum="1"
        android:paddingEnd="0dp"
        android:paddingStart="0dp"
        android:layout_margin="0dp">

        <Button
            android:layout_width="fill_parent"
            android:layout_height="23dp"
            android:text="NEWS"
            android:id="@+id/button"
            android:layout_weight="0.24"
            android:background="@android:color/holo_blue_bright"
            android:textColor="#ffffff"
            android:textSize="48dp" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="SPORTS"
            android:id="@+id/button2"
            android:layout_weight="0.24"
            android:background="@android:color/holo_blue_light"
            android:textColor="#ffffff"
            android:textSize="48dp" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:text="EVENTS"
            android:id="@+id/button3"
            android:layout_weight="0.24"
            android:background="@android:color/holo_blue_dark"
            android:textColor="#ffffff"
            android:textSize="48dp" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="24dp"
            android:text="MORE"
            android:id="@+id/button4"
            android:layout_weight="0.24"
            android:background="#f1f108"
            android:textSize="48dp" />
    </LinearLayout>
</RelativeLayout>

最佳答案

您只需从 Activity_main.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"

关于java - Android 应用程序 - 删除多余的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36269706/

相关文章:

java - Spring JSON 序列化器和反序列化器没有被调用

java - 以 Swing 形式浏览 HTML 文件

java - 在 project.properties 中设置构建路径

java - 为什么SimpleXYSeries不适合动态数据,以及如何实现 "dynamic data"XYSeries类?

java - 分割 ScrollView ,使其拉伸(stretch)一半屏幕,但忽略布局权重

android - 没有 xml 定义的 ImageView

android - 如何在设置闹钟前查看闹钟时间是否已过?

java - 从postgresql中批量插入的行中检索序列号

Android BLE 示例

Android Studio 引用库