Android ScrollView把手机屏幕上的一切都搞乱了
我在Android手机屏幕上的scrollview出现了这个问题。我的布局看起来就像我希望它出现在平板电脑屏幕上一样。然而,当在我的编辑器中将其切换到手机屏幕时(同时在手机上安装该应用程序),图像按钮会被挤压 以下是它在电话中的样子: 下面是我的XML代码。我已经读到,我可能需要创建另一个具有不同DPI的图像按钮布局,但我想知道是否有一种方法可以在没有DPI的情况下实现这一点Android ScrollView把手机屏幕上的一切都搞乱了,android,android-layout,scrollview,Android,Android Layout,Scrollview,我在Android手机屏幕上的scrollview出现了这个问题。我的布局看起来就像我希望它出现在平板电脑屏幕上一样。然而,当在我的编辑器中将其切换到手机屏幕时(同时在手机上安装该应用程序),图像按钮会被挤压 以下是它在电话中的样子: 下面是我的XML代码。我已经读到,我可能需要创建另一个具有不同DPI的图像按钮布局,但我想知道是否有一种方法可以在没有DPI的情况下实现这一点 <ScrollView xmlns:android="http://schemas.android.com/apk
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="4"
android:background="@drawable/pattern">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="@+id/APUButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:contentDescription="@string/APUButtonDescr"
android:scaleType="fitXY"
android:src="@drawable/apu" />
<ImageButton
android:id="@+id/LMSButton"
android:contentDescription="@string/LMSButtonDescr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/lms"
android:scaleType="fitXY"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="@+id/mailButton"
android:contentDescription="@string/mailButtonDescr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/mail"
android:scaleType="fitXY"/>
<ImageButton
android:id="@+id/scaButton"
android:contentDescription="@string/SCAButtonDescr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/sca"
android:scaleType="fitXY"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="@+id/libButton"
android:contentDescription="@string/libButtonDescr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/library"
android:scaleType="fitXY"/>
<ImageButton
android:id="@+id/ratingButton"
android:contentDescription="@string/ratingButtonDescr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/rating"
android:scaleType="fitXY"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ImageButton
android:id="@+id/curricularButton"
android:contentDescription="@string/curricularButtonDescr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/curricular"
android:scaleType="fitXY"/>
<ImageButton
android:id="@+id/aboutButton"
android:contentDescription="@string/settingsButtonDescr"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/about"
android:scaleType="fitXY"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
您可以尝试更改ImageButtons'scaleType
sfitCenter
可能会做你想做的事情。他们正在“挤压”,因为你正在制作图像fitXY
,而在平板电脑上,由于空间更大,列的宽度更大。但在手机上,列宽缩小到屏幕上指定的列数。非常感谢您的回答。但是,在我将fitXYs更改为fitCenter后,我仍然会收到长按钮。所以,按钮行之间有一个巨大的间隙。也有可能解决这个问题吗?我想要的是统一的方形图像按钮:)您正在拉伸图像,使其成为父级高度,同时使用match_parent
,这也将导致刮印外观,因为单元格的高度大于单元格的宽度