我試圖添加6個圖像作爲ImageButtons,但這些圖像是垂直拉伸的。見下圖:在LinearLayout中拉伸ImageViews
,你可以在上面的圖片中看到的所有imagebutons被垂直拉伸。我已經把它們放在drawable-xxxhdpi中。每張圖片的分辨率爲512x512。我也嘗試將它們放在mipmap-xxxhdpi或xxhdpi中,但沒有區別。這裏是我的代碼:
<RelativeLayout 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="#DCDCDC"
tools:context="MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3.4">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1" />
<ImageButton
android:id="@+id/radio_channel_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/background_radio_channel_one"
android:scaleType="fitXY" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1" />
<ImageButton
android:id="@+id/radio_channel_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/background_radio_channel_two"
android:scaleType="fitXY" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1" />
<ImageButton
android:id="@+id/radio_channel_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/background_radio_channel_three"
android:scaleType="fitXY" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="3.4">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1" />
<ImageButton
android:id="@+id/radio_channel_4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/background_radio_channel_four"
android:scaleType="fitXY" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1" />
<ImageButton
android:id="@+id/radio_channel_5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/background_radio_channel_five"
android:scaleType="fitXY" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1" />
<ImageButton
android:id="@+id/radio_channel_6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/background_radio_channel_six"
android:scaleType="fitXY" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.1" />
</LinearLayout>
</LinearLayout>
任何建議,以使它們看起來不正常伸展? 所有這些圖像都是PNG格式。
固定尺寸的圖像視圖:寬度= 512和高度= 512 –
嘗試刪除的android:scaleType =「fitXY」 –