简体   繁体   English

布局中不需要的填充

[英]Unwanted padding in layout

I'm new in the android programmation world and I'm facing some layout design problems. 我是android编程世界中的新手,并且面临一些布局设计问题。 There is a padding in the layout containing the two images, see the red arrow: 布局中包含两个图像的填充,请参见红色箭头:

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

As you can see I'm using the wrap_content attribute for both heigh and width, so I don't really understand why this is happening... 如您所见,我同时使用了wrap_content属性作为高度和宽度,因此我并不十分了解为什么会发生这种情况。

Here is my layout: 这是我的布局:

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

Any idea how to get rid of this ? 任何想法如何摆脱这个?

在您的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