如何让我的 xml 图片适合所有设备?
how can make my xml images fit for all devices?
我是 android 设计的新手,所以我希望我的主屏幕图像适合所有设备 我希望这个 MainScreen 页面适合所有设备。它有 3 张我已经赋予权重的图像,但如果我在选项卡上测试它似乎没有任何效果。它看起来不像我想要的样子,这是图片
这是我的 XML。我知道我不应该为高度提供 dp,但如何在不提供尺寸的情况下使它看起来像那样。
<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>
希望对您有所帮助
请参阅以下 xml 解决方案以获得您所需要的。
您始终可以通过播放 layout_weight 参数来更改每个视图元素的相对宽度和高度。就像以百分比给出 width/height :
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@android:drawable/btn_default"
android:scaleType="fitXY"
android:layout_weight="70"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="30">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/btn_default"
android:scaleType="fitXY"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/btn_default"
android:scaleType="fitXY"
android:layout_weight="1"/>
</LinearLayout>
我是 android 设计的新手,所以我希望我的主屏幕图像适合所有设备 我希望这个 MainScreen 页面适合所有设备。它有 3 张我已经赋予权重的图像,但如果我在选项卡上测试它似乎没有任何效果。它看起来不像我想要的样子,这是图片
这是我的 XML。我知道我不应该为高度提供 dp,但如何在不提供尺寸的情况下使它看起来像那样。
<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>
希望对您有所帮助
请参阅以下 xml 解决方案以获得您所需要的。
您始终可以通过播放 layout_weight 参数来更改每个视图元素的相对宽度和高度。就像以百分比给出 width/height :
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@android:drawable/btn_default"
android:scaleType="fitXY"
android:layout_weight="70"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="30">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/btn_default"
android:scaleType="fitXY"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/btn_default"
android:scaleType="fitXY"
android:layout_weight="1"/>
</LinearLayout>