简体   繁体   English

如何使我的xml图像适合所有设备?

[英]how can make my xml images fit for all devices?

I'm new to designing of android, So I want my main screen images fit to all devices i want this MainScreen page fit to be in all devices. 我是android设计的新手,所以我希望主屏幕图像适合所有设备,我希望MainScreen页面适合所有设备。 It has 3 images I have given weight but nothing seems to work if I test it on tab. 它具有3张我赋予了重量的图像,但是如果在选项卡上对其进行测试,则似乎无济于事。 Its not looking the way I want, here is the image 它不是我想要的样子,这是图像

在此处输入图片说明

here is my XML .I know I should not give dp for height but how to make it look like that without giving sizes. 这是我的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>

Use this code: 使用此代码:

    <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>

Hope this will help you 希望这个能对您有所帮助

See following xml solution to get what you need. 请参阅以下xml解决方案以获取所需内容。

You always can change relative width and height of the each view element by playing layout_weight parameter. 您始终可以通过播放layout_weight参数来更改每个视图元素的相对宽度和高度。 Its like give width/height in percents : 就像以百分比给出宽度/高度:

<?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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM