ImageView宽度与父级不匹配

时间:2016-06-10 23:08:34

标签: android android-layout android-linearlayout

我尝试使用LinearLayout在彼此之下拥有3个部分:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ImageEditing">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="vertical">

        <com.google.android.gms.ads.AdView
            android:id="@+id/adViewOfEditing"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad_unit_id" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/imageEditView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:layout_margin="0dp"
            android:scaleType="fitXY" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:background="#123456"
        android:gravity="center"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:src="@drawable/qa_gallery" />

        <ImageView
            android:id="@+id/zoom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:src="@drawable/qa_camera" />

        <ImageView
            android:id="@+id/erase"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:src="@drawable/qa_trash" />

        <ImageView
            android:id="@+id/crop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:src="@drawable/qa_view_post" />

        <ImageView
            android:id="@+id/undo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:src="@drawable/qa_reply_comment" />

    </LinearLayout>

</LinearLayout>

一切似乎都很好,但是中间部分的Image,它与父母尺寸不匹配,左边和右边都有间隙,其他部分都很好! ,这里有什么问题?

修改:屏幕截图enter image description here

1 个答案:

答案 0 :(得分:0)

我尝试了你的布局,一切都很完美:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="#343434"/>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageEditView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:layout_margin="0dp"
        android:background="#654321"
        android:scaleType="fitXY" />


</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:background="#123456"
    android:gravity="center"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/common_ic_googleplayservices" />

    <ImageView
        android:id="@+id/zoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/common_ic_googleplayservices"  />

    <ImageView
        android:id="@+id/erase"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/common_ic_googleplayservices"  />

    <ImageView
        android:id="@+id/crop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/common_ic_googleplayservices"  />

    <ImageView
        android:id="@+id/undo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/common_ic_googleplayservices"  />

</LinearLayout>

屏幕截图:sample screenshot