2013-10-29 40 views
-1

我有一個LinearLayout與另一個Linearlayout裏面。在第二個LinearLayout中,我有3個ImageViews,但它們都是在圖片中看到的。Android - 圖像並排無拉伸

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的drawable-ldpi,48x48的drawable-mdpi和64x64的drawable-hdpi。

+0

將scaleType更改爲CenterCrop –

+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後,已被棄用後者可以更好地保持長寬比。

+1

謝謝!!!!!!!我用src替換了背景,現在它可以工作! –