【发布时间】:2014-02-25 05:47:02
【问题描述】:
我在 stockoverflow 和链接上浏览了许多相关答案,例如 Supporting Different Screens 或 Screen Compatibility Mode
我创建了以下相对布局,并试图使其在所有 android 屏幕中看起来都一样。
我的图像非常适合 4.8 英寸手机,但是当我尝试使用 2.8 英寸显示屏或类似设备时,一些按钮会在其他按钮之上,而且它们不会缩小。
有没有人对如何改进有任何建议?
最好不要增加我的应用程序的大小。
提前致谢!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mm="http://millennialmedia.com/android/schema"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
tools:context=".MainActivity" >
<ImageButton
android:id="@+id/Switch_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="someMethod"
android:background="@drawable/switch_off"/>
<ImageView
android:id="@+id/warning_shot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/more"
android:onClick="someMethod" />
<ImageView
android:id="@+id/imageViewBatteryState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/Switch_off"
/>
<ImageView
android:id="@+id/sh"
android:layout_width="147dp"
android:layout_height="54dp"
android:layout_below="@+id/Switch_off"
android:layout_centerHorizontal="true"
android:background="@drawable/me"/>
<ImageView
android:id="@+id/sit"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="@+id/Switch_off"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/textViewBatteryInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="12sp"
android:textStyle="bold"
android:typeface="monospace"
android:layout_alignBottom="@+id/sit"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
【问题讨论】:
-
在布局中添加一个 ScrollView。
-
能否展示两张图片:一张使用 4.8" 屏幕,一张使用 2.8" 屏幕?
-
“我已经创建了以下相对布局,并且我试图让它在所有 android 屏幕中看起来都一样”——这不应该是你的目标。您的目标应该是为所有 Android 屏幕尺寸提供有用的 UI。这可能需要同一布局资源的多个版本,尤其是处理
-small2.8" 等屏幕。the first page that you linked to 涵盖了这一点。 -
ScrollView 将防止视图在您的布局中重叠。然而,支持多种屏幕尺寸以及让图像看起来不错的问题是更大的问题,它在您提供的链接中有所涵盖。坚持下去。
-
好的,非常感谢!
标签: android android-layout layout android-relativelayout imagebutton