Android 如何使我的布局适合所有屏幕
关于stockoverflow和link,我已经阅读了许多相关的答案,如orAndroid 如何使我的布局适合所有屏幕,android,android-layout,layout,android-relativelayout,imagebutton,Android,Android Layout,Layout,Android Relativelayout,Imagebutton,关于stockoverflow和link,我已经阅读了许多相关的答案,如or 我已经创建了以下相对布局,我正试图让它在所有android屏幕上看起来都一样 我的图像非常适合4.8英寸的手机,但当我尝试使用2.8英寸的显示屏或类似的东西时,有些按钮会盖在其他按钮上,并且不会收缩。 有人对如何改进这一点有什么建议吗? 最好不增加我的应用程序的大小 提前谢谢 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and
我已经创建了以下相对布局,我正试图让它在所有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>
我建议您使用线性布局而不是专门针对该问题的相对布局: 我的图像非常适合4.8英寸手机,但当我尝试使用2.8英寸手机时 英寸显示器或类似的东西,一些按钮放在 其他人,他们不会退缩 因为当您为Linearlayout设置方向时,它的子对象在任何分辨率或屏幕大小上都不会彼此领先 如果你给他们权重,那么每个设备的视图都将处于固定位置 例如,在项目中放置Xml,并在任何分辨率中检查此项,它将给出相同的结果 XML:
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 3" />
</LinearLayout>
</LinearLayout>
在布局中添加一个滚动视图。能否显示两张图片:一张使用4.8英寸屏幕,另一张使用2.8英寸屏幕?“我创建了以下相对布局,并试图使其在所有android屏幕上看起来都一样”——这不应该是您的目标。您的目标应该是为所有Android屏幕大小提供一个有用的UI。这可能需要相同布局资源的多个版本,特别是对于处理-小型屏幕(如2.8版)“。这包含在.A中,将防止视图在布局中重叠。支持多个屏幕尺寸,让图像看起来更漂亮,这是一个更大的问题,您提供的链接中已经介绍了这个问题。坚持下去。好的,非常感谢!如果您有任何疑问,请与我分享。在我的代码中无法使其工作:/,即使在我添加了权重
和线性布局
之后,您是否可以发送您在上述xml中使用的所有图像?所以我可以测试它。