Android 如何使我的xml图像适合所有设备?
我对android的设计还不熟悉,所以我希望我的主屏幕图像适合所有设备我希望这个主屏幕页面适合所有设备。它有3张图片,我给了它权重,但若我在标签上测试它,似乎并没有任何效果。这不是我想要的样子,这是图片 这是我的XML。我知道我不应该给出高度的dp,但如何在不给出大小的情况下使它看起来像那样Android 如何使我的xml图像适合所有设备?,android,android-layout,android-imageview,Android,Android Layout,Android Imageview,我对android的设计还不熟悉,所以我希望我的主屏幕图像适合所有设备我希望这个主屏幕页面适合所有设备。它有3张图片,我给了它权重,但若我在标签上测试它,似乎并没有任何效果。这不是我想要的样子,这是图片 这是我的XML。我知道我不应该给出高度的dp,但如何在不给出大小的情况下使它看起来像那样 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://
<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"
tools:context="com.example.zeba.broccoli.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<ImageView
android:id="@+id/ms1"
android:layout_width="match_parent"
android:layout_height="374dp"
android:layout_weight="7"
android:scaleType="fitXY"
android:src="@drawable/avatar" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageView
android:id="@+id/ms2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/ee"
android:layout_weight=".5" />
<ImageView
android:id="@+id/ms3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/dd"
android:layout_weight=".5" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
使用以下代码:
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7">
<ImageView
android:id="@+id/ms1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3">
<ImageView
android:id="@+id/ms2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/ms3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
希望这将帮助您使用此代码:
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7">
<ImageView
android:id="@+id/ms1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3">
<ImageView
android:id="@+id/ms2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/ms3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
希望这将帮助您查看以下xml解决方案,以获得所需的内容 始终可以通过播放layout_weight参数来更改每个视图元素的相对宽度和高度。类似于以百分比表示宽度/高度:
<?xml version="1.0" encoding="utf-8"?>
请参阅以下xml解决方案以获取所需内容 始终可以通过播放layout_weight参数来更改每个视图元素的相对宽度和高度。类似于以百分比表示宽度/高度:
<?xml version="1.0" encoding="utf-8"?>
图像的固定尺寸可能因设备而异。将wrap_内容用于尺寸,并告诉设计师根据不同的屏幕分辨率设计图像。如果您不想给出尺寸,则需要将不同尺寸的图像放置在单独的可绘制文件夹中,如可绘制xhdpi、可绘制xxhdpi等,如果我根据hdpi等设备调整图像大小,xxhdpi..像那样..它可以合适吗?没关系,但在这里我可以给我的图像完美的外观而不给出高度大小..例如这里我给了374dp..我不应该给它我想用重量来建造..但是重量不起作用这里图像的固定尺寸可以随设备而变化。将wrap_内容用于尺寸,并告诉设计师根据不同的屏幕分辨率设计图像。如果您不想给出尺寸,则需要将不同尺寸的图像放置在单独的可绘制文件夹中,如可绘制xhdpi、可绘制xxhdpi等,如果我根据hdpi等设备调整图像大小,xxhdpi..像那样..它可以合适吗?没关系,但在这里我可以在不给出身高尺寸的情况下给我的图像完美的外观..例如这里我给了374dp..我不想给它我想用重量来建造..但重量不起作用我已经用ic_启动器替换了你的图像资源。所以根据你的需要进行相应的放置。谢谢。但是我需要在尺寸上做一些工作,因为有些设备的图像不适合。可能需要调整尺寸。它会自动调整。只要用更多的设备进行测试。你会明白的。我已经用ic_启动器替换了你的图像资源。所以根据你的需要进行相应的放置。谢谢。但是我需要在尺寸上做一些工作,因为有些设备的图像不适合。可能需要调整尺寸。它会自动调整。只要用更多的设备测试一下,你就会明白了。