我试图添加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” –