ImageView不适合我的linearlayout高度

时间:2016-06-06 10:13:15

标签: android imageview android-linearlayout android-layout-weight

我的linearLayout中有5个imageview(layout_weight = 2)(weightSum = 10) 所有的imageview都有0dp的宽度和wrap_content的高度,但我总是有一个top和bot边距...... 当我使用设计视图时,如果我尝试手动调整我的linearlayout高度(通过扩展边框),这最后会被设置为修复值,这不是我想要的原因(不再动态)

enter image description here

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/fond">

    <TextView/>

    <LinearLayout>

        <ImageView/>

        <TextView/>

        <TextView/>

        <ImageView/>

    </LinearLayout>

    <TextView
        android:text="ECRANS DISPONIBLES"
        android:drawableLeft="@drawable/selectsite_picto_search"
        android:drawablePadding="2dip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        android:textStyle="normal"
        android:layout_margin="10dp"
        android:id="@+id/homeScreenAvailableTextView"
        android:textColor="#FFF" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:background="#26FFFFFF"
        android:weightSum="10">

        <ImageView
            android:id="@+id/item_home_screen1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:src="@drawable/home_poster1"
            android:layout_weight="2"/>

        <ImageView
            android:id="@+id/item_home_screen2"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:src="@drawable/home_poster2"
            android:layout_weight="2"/>

        <ImageView
            android:id="@+id/item_home_screen3"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:src="@drawable/home_poster3"
            android:layout_weight="2"/>

        <ImageView
            android:id="@+id/item_home_screen4"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:src="@drawable/home_poster4"
            android:layout_weight="2"/>

        <ImageView
            android:id="@+id/item_home_screen5"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:src="@drawable/home_poster5"
            android:layout_weight="2"/>

    </LinearLayout>

    <TextView/>

    <TextView/>

    <TextView/>

    <TextView/>
</LinearLayout>

</ScrollView>

3 个答案:

答案 0 :(得分:0)

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="#26FFFFFF"
    android:weightSum="10">

    <ImageView
        android:id="@+id/item_home_screen1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:src="#AAAAAA"
        android:layout_weight="2"/>

    <ImageView
        android:id="@+id/item_home_screen2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:src="#BBBB00"
        android:layout_weight="2"/>

    <ImageView
        android:id="@+id/item_home_screen3"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:src="#CC00CC"
        android:layout_weight="2"/>

    <ImageView
        android:id="@+id/item_home_screen4"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:src="#DDBDDD"
        android:layout_weight="2"/>

    <ImageView
        android:id="@+id/item_home_screen5"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:src="#00DDDD"
        android:layout_weight="2"/>

</LinearLayout>

//试试这个

答案 1 :(得分:0)

请为android:scaleType="fitXY"提供所有图片浏览量。这会将imageview的高度设置为与线性布局的高度相同。

答案 2 :(得分:0)

我终于找到了解决办法 android:scaleType =&#34; fitCenter&#34; 和 在每个imageView中 android:adjustViewBounds =&#34; true&#34; ,并将layout_height =&#34; wrap_content&#34;到linearLayout

    <TextView
        android:text="ECRANS DISPONIBLES"
        android:drawableLeft="@drawable/selectsite_picto_near"
        android:drawablePadding="2dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="12sp"
        android:textStyle="normal"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="20dp"
        android:id="@+id/homeScreenAvailableTextView"
        android:textColor="#FFF" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="#26FFFFFF"
        android:weightSum="10">
  •     <ImageView
            android:id="@+id/item_home_screen2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@drawable/home_poster2"
            android:layout_weight="2"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true" />
    
        <ImageView
            android:id="@+id/item_home_screen3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@drawable/home_poster3"
            android:layout_weight="2"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true" />
    
        <ImageView
            android:id="@+id/item_home_screen4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@drawable/home_poster4"
            android:layout_weight="2"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true" />
    
        <ImageView
            android:id="@+id/item_home_screen5"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@drawable/home_poster5"
            android:layout_weight="2"
            android:scaleType="fitStart"
            android:adjustViewBounds="true" />
    
    </LinearLayout>