我是否应该创建不同的布局文件夹来存储我的 xml 布局文件。在不同的屏幕尺寸上支持我的应用程序?
我开发了一个应用程序,当添加可绘制对象时,它会自动创建不同的尺寸,如 xdpi ldpi 等,但布局 xml 文件不会自动创建以支持不同的屏幕尺寸。我应该这样做吗?我还将使用 support-screen 标签编辑 list 文件以支持不同的尺寸。这就是全部吗??它还会支持我的横向或纵向模式吗?请确认我。我是堆栈和 android 开发的新手。
编辑: 我相信不同文件夹中的不同布局文件..将只是彼此的副本,代码中仅显示文件夹名称更改广告
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
这是我的布局 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"
tools:context="com.example.root.meeransunday.MainActivity">
<Button
android:id="@+id/button1"
android:layout_width="200dp"
android:layout_height="90dp"
android:text="Send Mobile"
android:drawableLeft="@mipmap/sms"
android:layout_alignParentBottom="true"
android:layout_marginRight="-1dp"
android:layout_marginLeft="-3dp"
android:layout_marginBottom="-4dp"
android:onClick="message"/>
<Button
android:id="@+id/button2"
android:layout_width="200dp"
android:layout_height="90dp"
android:text="QR Code"
android:drawableLeft="@mipmap/qr"
android:layout_marginLeft="190dp"
android:layout_marginRight="-20dp"
android:layout_marginBottom="-4dp"
android:layout_alignParentBottom="true"
android:onClick="scan"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:text=" My Account Balance"
android:textColor="#0D47A1"
/>
<TextView
android:text="PKR 1527.87"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_centerHorizontal="true"
android:drawableLeft="@mipmap/money"
android:textSize="35sp"
android:id="@+id/textView2"
/>
</RelativeLayout>
list 文件:
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"
android:resizeable="true"/>
但它不适用于 4 英寸屏幕。
最佳答案
如果布局相同,则无需创建多个布局文件,您应该使用不同的尺寸文件来调整元素的大小。
如果您希望您的应用程序在 hdpi 设备上看起来与在 xxxhdpi 设备上看起来不同,或者如果您有手机和平板电脑版本的屏幕,那么您应该使用多个布局文件。
关于android - 我应该为不同的 android 手机制作不同的布局(xml 文件)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43179038/