【问题标题】:Layout differs on same set of screen同一组屏幕上的布局不同
【发布时间】:2014-05-05 08:02:24
【问题描述】:

我正在开发一个针对所有 android 版本的所有屏幕的 UI。 现在,我正在两个设备上进行测试,sony experia Neo v 具有规格: 480 x 854 像素,3.7 英寸(~265 ppi 像素密度)Android OS- 2.3.4, 和其他设备 HTC Desire X Dual SIM 具有以下规格: 480 x 800 像素,4.0 英寸(~233 ppi 像素密度)Android Os- 4.1.1。

这里的问题是,根据我的理解,这两个设备都是普通屏幕和 hdpi, 他们也都从同一个布局文件夹中挑选,但是这两种设备的 UI 差别很大。 HTC 按预期呈现,但 Sony Experia 上的 UI 是一场灾难。 我面临的主要问题是 Eclipse 预览屏幕中的 UI 外观与 HTC 相同,但 Sony experia 似乎无法很好地呈现它。

我注意到的另一点是当我使用配置运行模拟器时: 3.7 FWVGA 480*854:hdpi android-2.3.4,和Sony Experia config一模一样,渲染也和sony experia一模一样, 但是一旦我将模拟器编辑为 andrdoid 4.1.1 3.7 FWVGA 480*854:hdpi 它就会开始按预期显示。 所以,我有点困惑,Ui 显示是否也取决于 Android 操作系统版本?

以下是我的布局代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/linear_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"

        android:weightSum="3"
        android:gravity="center" >

        <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"

        android:weightSum="3"
        android:gravity="center"
        android:baselineAligned="false">

        <FrameLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" 
            android:layout_marginTop="4dp"
            android:layout_marginBottom="8dp">

            <Button
                android:id="@+id/availbtn"
                android:layout_width="102dp"
                android:layout_height="33dip"
                android:background="@drawable/badge_button_selected"
                android:text="Available"

                android:layout_marginTop="13dp"
                android:textColor="#000000" 
                android:textAppearance="@android:style/TextAppearance.Small"/>

            <TextView
                android:id="@+id/txt_avail_coupon_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="2dp"
                android:layout_gravity="top|right"
                android:background="@drawable/badge_circle_selected"
                android:text="07"
                android:textColor="#FFF"
                android:textSize="12sp"
                android:textStyle="bold" />
        </FrameLayout>

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
             android:layout_marginTop="4dp"
            android:layout_marginBottom="8dp" >

            <Button
                android:id="@+id/usedbtn"
                android:layout_width="102dp"
                android:layout_height="33dip"
                android:background="@drawable/badge_button_nselected"
                android:text="Used"
                android:textAppearance="@android:style/TextAppearance.Small"
                android:layout_marginTop="13dp"
                android:textColor="#000000" />

            <TextView
                android:id="@+id/txt_used_coupon_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="2dp"
                android:layout_gravity="top|right"
                android:background="@drawable/badge_circle_nselected"
                android:text="10"
                android:textColor="#FFF"
                android:textSize="12sp"
                android:textStyle="bold" />
        </FrameLayout>

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" 
             android:layout_marginTop="4dp"
            android:layout_marginBottom="8dp">

            <Button
                android:id="@+id/expirebtn"
                android:layout_width="102dp"
                android:layout_height="33dip"
                android:background="@drawable/badge_button_nselected"
                android:text="Expired"
                android:textAppearance="@android:style/TextAppearance.Small"
                android:layout_marginTop="13dp"
                android:textColor="#000000" />

            <TextView
                android:id="@+id/txt_expired_coupon_count"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="2dp"
                android:layout_gravity="top|right"
                android:background="@drawable/badge_circle_nselected"
                android:text="01"
                android:textColor="#FFF"
                android:textSize="12sp"
                android:textStyle="bold" />
        </FrameLayout>


        </LinearLayout>
    </LinearLayout>

    <View
        android:id="@+id/divider"
        android:layout_width="fill_parent"
        android:layout_height="5dip"
        android:layout_below="@+id/linear_button"
        android:background="@android:color/darker_gray" />

    <ListView
        android:id="@+id/coupons_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/divider" >
    </ListView>

</RelativeLayout>

以下是 android-2.3.4 上 3.7 FWVGA 480*854:hdpi 和 android 4.1.1 上 3.7 FWVGA 480*854:hdpi 的 UI 屏幕截图:

【问题讨论】:

    标签: android android-layout screen


    【解决方案1】:
    // try this way,hope this will help you...
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <LinearLayout
            android:id="@+id/linear_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
    
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_marginTop="4dp"
                    android:layout_marginBottom="8dp">
    
                    <Button
                        android:id="@+id/availbtn"
                        android:layout_width="102dp"
                        android:layout_height="33dp"
                        android:background="@drawable/badge_button_selected"
                        android:text="Available"
                        android:layout_marginTop="13dp"
                        android:textColor="#000000"
                        android:textAppearance="@android:style/TextAppearance.Small"/>
    
                    <TextView
                        android:id="@+id/txt_avail_coupon_count"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="2dp"
                        android:layout_gravity="top|right"
                        android:background="@drawable/badge_circle_selected"
                        android:text="07"
                        android:textColor="#FFF"
                        android:textSize="12sp"
                        android:textStyle="bold" />
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_marginTop="4dp"
                    android:layout_marginBottom="8dp" >
    
                    <Button
                        android:id="@+id/usedbtn"
                        android:layout_width="102dp"
                        android:layout_height="33dp"
                        android:background="@drawable/badge_button_nselected"
                        android:text="Used"
                        android:textAppearance="@android:style/TextAppearance.Small"
                        android:layout_marginTop="13dp"
                        android:textColor="#000000" />
    
                    <TextView
                        android:id="@+id/txt_used_coupon_count"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="2dp"
                        android:layout_gravity="top|right"
                        android:background="@drawable/badge_circle_nselected"
                        android:text="10"
                        android:textColor="#FFF"
                        android:textSize="12sp"
                        android:textStyle="bold" />
                </LinearLayout>
    
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:layout_marginTop="4dp"
                    android:layout_marginBottom="8dp">
    
                    <Button
                        android:id="@+id/expirebtn"
                        android:layout_width="102dp"
                        android:layout_height="33dp"
                        android:background="@drawable/badge_button_nselected"
                        android:text="Expired"
                        android:textAppearance="@android:style/TextAppearance.Small"
                        android:layout_marginTop="13dp"
                        android:textColor="#000000" />
    
                    <TextView
                        android:id="@+id/txt_expired_coupon_count"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginRight="2dp"
                        android:layout_gravity="top|right"
                        android:background="@drawable/badge_circle_nselected"
                        android:text="01"
                        android:textColor="#FFF"
                        android:textSize="12sp"
                        android:textStyle="bold" />
                </LinearLayout>
    
    
        </LinearLayout>
    
        <View
            android:id="@+id/divider"
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="@android:color/darker_gray" />
    
        <ListView
            android:id="@+id/coupons_listview"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
        </ListView>
    
    </LinearLayout>
    

    【讨论】:

    • 我不明白你的逻辑你为什么用LinearLayout替换我的FrameLayout,这太荒谬了。这将如何产生相同的结果,您是否尝试过此代码? .. 你的答案应该被否决。
    • 我出于某种目的使用了 FrameLayout,以获得所需的 UI。请在回答之前尝试阅读问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多