[英]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参数来更改每个视图元素的相对宽度和高度。 就像以百分比给出宽度/高度:
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.