Android - Imageviews并排没有拉伸

时间:2013-10-29 23:14:13

标签: android image layout imageview android-linearlayout

我有一个LinearLayout,里面有另一个Linearlayout。在第二个LinearLayout中,我有3个ImageView,但它们都被拉伸,如图所示。

Layout with stretched ImageViews

这是我的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:orientation="vertical" >

<TextView
    android:id="@+id/contact_data"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@drawable/bubble"
    android:gravity="center"
    android:padding="10sp"
    android:text="@string/contact_data"
    android:textColor="#000000" />

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_margin="10dp"
    android:background="@android:color/darker_gray" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/phonenumber"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/phone"
        android:clickable="true"
        android:onClick="onClick" />

    <ImageView
        android:id="@+id/emailaddress"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/email"
        android:clickable="true"
        android:onClick="onClick" />

    <ImageView
        android:id="@+id/internetaddress"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@drawable/internet"
        android:clickable="true"
        android:onClick="onClick" />
  </LinearLayout>

  </LinearLayout>

有什么问题?

PS:每张图片有3种尺寸:32x32 in drawable-ldpi,48x48 in drawable-mdpi,64x64 in drawable-hdpi。

1 个答案:

答案 0 :(得分:1)

您目前正在将每个ImageView的尺寸设置为android:layout_width="match_parent"android:layout_height="fill_parent"

您确定不想使用wrap_content吗?

另请注意fill_parent means the same things as match_parent,自API级别8以来已弃用。


进一步检查时,您还设置了ImageView的背景而不是 src ,后者将更好地保持宽高比。< / p>