【问题标题】:Layout item positions and sizes get changed for different devices不同设备的布局项目位置和大小发生变化
【发布时间】:2016-05-12 13:40:19
【问题描述】:

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

在我的 xiomi mi4c (lollipop) 屏幕上看起来不错

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

我希望我的应用在所有设备上看起来都与 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>

【问题讨论】:

  • 在线性布局中同时使用圆形进度视图 - 水平方向与 weightsum 2 并在此线性布局中添加两个圆形进度并设置 layout_weight
  • 谢谢@Saurabh。这很有帮助。
  • 谢谢@DixitPanchal。我试过了。它有效,但如果我将它放在线性布局中,则会从 4 个侧面裁剪更大的进度视图
  • 我对你的评论投了票。

标签: android xml layout


【解决方案1】:

试试这个:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    • 1970-01-01
    • 2019-07-29
    • 2016-08-16
    • 2011-08-06
    相关资源
    最近更新 更多