不同设备的布局项位置和大小会发生变化

时间:2016-05-12 05:00:02

标签: android xml layout

我使用两个Android操作系统在genymotion模拟器中测试了我的应用程序。棒棒糖和冰淇淋三明治。两台设备都运行良好。问题是当我在真实设备中测试时,项目位置和大小会发生变化。

在我的xiomi mi4c(棒棒糖)屏幕上看起来不错 Mi4c Screenshot

但是在micromax canves(Ice Cream Sandwich)中会出现这个问题 Micromax Screenshot

我希望我的应用程序看起来与我的mi4c中的每个设备相同。

这是我的xml文件。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout_widget"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/bg_register"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.ceatkelanisrilanka.dushanmadushanka.ceat.CeatMainActivity"
        tools:showIn="@layout/activity_ceat_main">

        <include
            android:id="@+id/app_bar"
            layout="@layout/app_toolbar_welcome_menu"></include>

        <LinearLayout
            android:id="@+id/mainLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/firstLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingTop="5dp">

                <LinearLayout
                    android:id="@+id/enMonth"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:paddingLeft="10dp"
                    android:paddingStart="10dp">

                    <TextView
                        android:id="@+id/txtMonth"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Month"
                        android:textColor="#ffffff"
                        android:textSize="24sp" />

                    <TextView
                        android:id="@+id/yearTextV"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="year"
                        android:layout_gravity="center"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="#ffffff" />


                </LinearLayout>

                <LinearLayout
                    android:id="@+id/pViewLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">

                    <com.rey.material.widget.ProgressView
                        android:id="@+id/pViewew"
                        cpd_strokeColor="@android:color/holo_red_dark"
                        cpd_strokeSecondaryColor="@android:color/holo_blue_bright"
                        cpd_strokeSize="25dp"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        app:pv_autostart="true"
                        app:pv_circular="true"
                        app:pv_progressMode="indeterminate"
                        app:pv_progressStyle="@style/Material.Drawable.CircularProgress" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/snMonthLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:orientation="vertical"
                    android:paddingEnd="10dp"
                    android:paddingRight="10dp">

                    <TextView
                        android:id="@+id/txtMonthSn"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:text="MonthSn"
                        android:textColor="#ffffff"
                        android:textSize="24sp" />

                </LinearLayout>

            </LinearLayout>

            <RelativeLayout
                android:id="@+id/secondLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingTop="15dp">

                <com.github.lzyzsd.circleprogress.ArcProgress
                    android:id="@+id/arc_progress"
                    android:layout_width="220dp"
                    android:layout_height="220dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginStart="15dp" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:paddingRight="15dp"
                    android:paddingTop="25dp">

                    <com.hookedonplay.decoviewlib.DecoView
                        android:id="@+id/dynamicArcView"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:padding="5dp" />

                    <TextView
                        android:id="@+id/pView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="0 %"
                        android:textColor="#4B73C4"
                        android:textSize="20sp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Precentage"
                        android:textColor="#4B73C4"
                        android:textSize="15sp" />

                </LinearLayout>
            </RelativeLayout>

            <LinearLayout
                android:id="@+id/thirdLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:paddingLeft="10dp"
                    android:paddingTop="20dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtMtar"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Monthly Target"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtMAch"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Achievment"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtPre"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Percentage"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />

                    </LinearLayout>


                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1.1"
                    android:orientation="vertical"
                    android:paddingTop="20dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtTarget"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="M"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtAchievement"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="M"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />


                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtCollection"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="M"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />


                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:paddingTop="20dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <Button
                            android:id="@+id/bTon"
                            android:layout_width="120dp"
                            android:layout_height="wrap_content"
                            android:text="Ton"
                            android:textColor="@color/border_gray" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">


                        <Button
                            android:id="@+id/bValue"
                            android:layout_width="120dp"
                            android:layout_height="wrap_content"
                            android:text="Value"
                            android:textColor="@color/border_gray" />


                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <Button
                            android:id="@+id/bCollection"
                            android:layout_width="120dp"
                            android:layout_height="wrap_content"
                            android:text="Collection"
                            android:textColor="@color/border_gray" />

                    </LinearLayout>

                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.ceatkelanisrilanka.dushanmadushanka.ceat.fragments.NavigationDrawerFragment"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer"></fragment>


</android.support.v4.widget.DrawerLayout>

1 个答案:

答案 0 :(得分:0)

试试这个:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout_widget"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ff0000"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include
            android:id="@+id/app_bar"
            layout="@layout/app_toolbar_welcome_menu"></include>

        <LinearLayout
            android:id="@+id/mainLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/firstLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingTop="5dp">

                <LinearLayout
                    android:id="@+id/enMonth"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:paddingLeft="10dp"
                    android:paddingStart="10dp">

                    <TextView
                        android:id="@+id/txtMonth"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Month"
                        android:textColor="#ffffff"
                        android:textSize="24sp" />

                    <TextView
                        android:id="@+id/yearTextV"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="year"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="#ffffff" />


                </LinearLayout>

                <LinearLayout
                    android:id="@+id/pViewLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical">

                    <com.rey.material.widget.ProgressView
                        android:id="@+id/pViewew"
                        cpd_strokeColor="@android:color/holo_red_dark"
                        cpd_strokeSecondaryColor="@android:color/holo_blue_bright"
                        cpd_strokeSize="25dp"
                        android:layout_width="50dp"
                        android:layout_height="50dp"
                        app:pv_autostart="true"
                        app:pv_circular="true"
                        app:pv_progressMode="indeterminate"
                        app:pv_progressStyle="@style/Material.Drawable.CircularProgress" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/snMonthLayout"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:orientation="vertical"
                    android:paddingEnd="10dp"
                    android:paddingRight="10dp">

                    <TextView
                        android:id="@+id/txtMonthSn"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:text="MonthSn"
                        android:textColor="#ffffff"
                        android:textSize="24sp" />

                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:id="@+id/secondLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:padding="10dp">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight=".5"
                    android:padding="5dp">

                    <com.github.lzyzsd.circleprogress.ArcProgress
                        android:id="@+id/arc_progress"
                        android:layout_width="220dp"
                        android:layout_height="220dp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_weight=".5"
                    android:gravity="center"
                    android:layout_gravity="center_vertical"
                    android:orientation="vertical"
                    android:padding="5dp">

                    <com.hookedonplay.decoviewlib.DecoView
                        android:id="@+id/dynamicArcView"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:padding="5dp" />

                    <TextView
                        android:id="@+id/pView"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="0 %"
                        android:textColor="#4B73C4"
                        android:textSize="20sp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Precentage"
                        android:textColor="#4B73C4"
                        android:textSize="15sp" />

                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/thirdLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:padding="10dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:paddingLeft="10dp"
                    android:paddingTop="20dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtMtar"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Monthly Target"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtMAch"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Achievment"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_vertical"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtPre"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Percentage"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:paddingTop="20dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtTarget"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="M"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtAchievement"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="M"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />


                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <TextView
                            android:id="@+id/txtCollection"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="M"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="#ffffff" />


                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:paddingTop="20dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <Button
                            android:id="@+id/bTon"
                            android:layout_width="120dp"
                            android:layout_height="wrap_content"
                            android:text="Ton"
                            android:textColor="#000000" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">


                        <Button
                            android:id="@+id/bValue"
                            android:layout_width="120dp"
                            android:layout_height="wrap_content"
                            android:text="Value"
                            android:textColor="#000000" />


                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:orientation="horizontal">

                        <Button
                            android:id="@+id/bCollection"
                            android:layout_width="120dp"
                            android:layout_height="wrap_content"
                            android:text="Collection"
                            android:textColor="#000000" />

                    </LinearLayout>

                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>


    <!--<fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.ceatkelanisrilanka.dushanmadushanka.ceat.fragments.NavigationDrawerFragment"
        android:layout_width="@dimen/nav_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer"></fragment>-->


</android.support.v4.widget.DrawerLayout>