簡體   English   中英

布局中不需要的填充

[英]Unwanted padding in layout

我是android編程世界中的新手,並且面臨一些布局設計問題。 布局中包含兩個圖像的填充,請參見紅色箭頭:

http://www.servimg.com/view/13840630/200

如您所見,我同時使用了wrap_content屬性作為高度和寬度,因此我並不十分了解為什么會發生這種情況。

這是我的布局:

    <LinearLayout 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"
    tools:context="com.scimoon.henri.scimoon.Game"
    android:background="@color/white"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="horizontal"
        android:paddingTop="15dp"
        android:paddingBottom="5dp"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/darkBlue"
        android:id="@+id/back">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/back"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="@string/back"
            android:textColor="@color/white"
            android:textSize="35dp"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1">
        <ImageView
            android:id="@+id/bt_bleu"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/bt_bleu"
            android:layout_weight="1"/>
        <ImageView
            android:id="@+id/bt_rouge"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/bt_rouge"
            android:layout_weight="1"/>
    </LinearLayout>


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center_horizontal"
        android:layout_weight="1">

        <ImageView
            android:id="@+id/bt_jaune"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:src="@drawable/bt_jaune"
            android:layout_weight="1"/>

        <ImageView
            android:id="@+id/bt_vert"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/bt_vert"
            android:layout_margin="0dp"
            android:padding="0dp"
            android:layout_weight="1"/>

    </LinearLayout>
</LinearLayout>

任何想法如何擺脫這個?

在您的res文件夾中,有一個名為values的文件夾,其中應存在一個名為dimens.xml的文件,打開該文件,您會發現邊距設置為1dp或0dp

在兩個包含圓圈的LinearLayouts上刪除android:layout_weight="1"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM