如何调整imageview的大小以适应屏幕? Android的

时间:2014-02-26 19:28:51

标签: android

所以我在垂直视图中有7个图像,第一个位于屏幕顶部,第7个位于屏幕底部(2.7英寸)。当我在更大的屏幕(4.7英寸)中安装此应用程序时,第一个图像位于顶部屏幕,但第7个图像位于屏幕中间,我希望它与2.7英寸一样完美。我知道图像应该自动增加,但我不知道该怎么做。

谢谢

<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:background="@drawable/wallpaper_08"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView9"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:src="@drawable/ic_launcher" />


</LinearLayout>

2 个答案:

答案 0 :(得分:1)

您可以将所有ImageView设置为layout_height为 0dp ,layout_weight为 1
这将平均分配垂直空间

所以:

<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:background="@drawable/wallpaper_08"
    android:orientation="vertical"
    >
    <ImageView
        android:id="@+id/imageView9"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
    />
    <ImageView
        android:id="@+id/imageView8"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
    />
    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
    />
    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
    />
    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
    />
    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
    />
    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher"
    />
</LinearLayout>

答案 1 :(得分:0)

使用android:layout_weight =“”。在所有ImageView中应用以下

android:layout_height="0px"
android:layout_weight="1"