简体   繁体   English

通知中的模拟器,设备,Android Studio布局差异

[英]Emulator, Device, Android Studio Layout Differences in Notification

I'm trying to layout a fragment for a notification... the emulator and layout in the Android Studio designer are fine. 我正在尝试为通知布局片段... Android Studio设计器中的模拟器和布局都很好。

(Emulator Example) (仿真器示例)

在模拟器上的布局

(Designer Example) (设计师示例) android studio中的布局

But when the app is run on the target device the layout is not aligned properly. 但是,当应用程序在目标设备上运行时,布局未正确对齐。

(Layout on Device) (设备上的布局) 设备上的布局

The device is an s7 edge with resolution 1440*2560, screen size 5.5 inch, and 360dp smallest width. 该设备是s7边缘,分辨率为1440 * 2560,屏幕尺寸为5.5英寸,最小宽度为360dp。

I created an emulator based on these specs and am running the app on it. 我根据这些规格创建了一个模拟器,并在其上运行该应用程序。

The layout is in res folder layout-sw360dp-xxxhdpi 布局在res文件夹中layout-sw360dp-xxxhdpi

There are other layout folders: 还有其他布局文件夹:

layout-sw320dp-hdpi 布局-sw320dp-hdpi

layout-sw360dp-xhdpi 布局-sw360dp-xhdpi

layout-sw360dp-xxhdpi 布局-sw360dp-xxhdpi

layout-sw411dp-xxxhdpi 布局-sw411dp-xxxhdpi

I have tried scaling imageviews, fitxy, fitstart, etc... 我尝试缩放图像视图,fitxy,fitstart等...

I have carefully checked the density pixel sizes for each imageview, layout, and background. 我已经仔细检查了每个imageview,布局和背景的密度像素大小。

Layout XML: 布局XML:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/media_notification_large_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="0dp">

<ImageView
android:id="@+id/note_far_left"
android:layout_width="6.5dp"
android:layout_height="112dp"
android:layout_alignParentLeft="true"
android:src="@mipmap/note_far_left" />

<ImageView
android:id="@+id/note_picture_top"
android:layout_width="133.5dp"
android:layout_height="13.5dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/note_far_left"
android:src="@mipmap/note_picture_top" />

<ImageView
android:id="@+id/note_picture"
android:layout_width="85dp"
android:layout_height="85dp"
android:layout_below="@id/note_picture_top"
android:layout_toRightOf="@id/note_far_left"
android:background="@drawable/silver_note"
android:src="@drawable/silver_note" />

<ImageView
android:id="@+id/note_picture_bottom"
android:layout_width="85dp"
android:layout_height="13.5dp"
android:layout_below="@id/note_picture"
android:layout_toRightOf="@id/note_far_left"
android:src="@mipmap/note_picture_bottom" />

<ImageView
android:id="@+id/note_title_text_top"
android:layout_width="172.75dp"
android:layout_height="6.5dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/note_picture_top"
android:src="@mipmap/note_title_text_top" />

<ImageView
android:id="@+id/note_picture_right_top"
android:layout_width="48.5dp"
android:layout_height="32.25dp"
android:layout_below="@id/note_picture_top"
android:layout_toRightOf="@id/note_picture"
android:src="@mipmap/note_picture_right_top" />

<ImageView
android:id="@+id/note_picture_right_bottom"
android:layout_width="14.25dp"
android:layout_height="66.25dp"
android:layout_below="@id/note_picture_right_top"
android:layout_toRightOf="@id/note_picture"
android:src="@mipmap/note_picture_right_bottom" />

<ImageView
android:id="@+id/note_title_text_bottom"
android:layout_width="172.75dp"
android:layout_height="13.5dp"
android:layout_below="@+id/note_title"
android:layout_toRightOf="@id/note_picture_right_top"
android:src="@mipmap/note_title_text_bottom" />

<TextView
android:id="@+id/note_shb1"
android:layout_width="68.5dp"
android:layout_height="13.25dp"
android:layout_below="@id/note_title_text_bottom"
android:layout_margin="0dp"
android:layout_toRightOf="@id/note_picture_right_bottom"
android:background="@mipmap/note_shb1"
android:fontFamily="@font/digital_7_mono"
android:gravity="center"
android:text="Shuffle"
android:textColor="@color/colorAccent"
android:textSize="9.25sp" />

<TextView
android:id="@+id/note_shb2"
android:layout_width="68.5dp"
android:layout_height="13.25dp"
android:layout_below="@id/note_title_text_bottom"
android:layout_margin="0dp"
android:layout_toRightOf="@id/note_shb1"
android:background="@mipmap/note_shb2"
android:fontFamily="@font/digital_7_mono"
android:gravity="center"
android:text="Hands Free"
android:textColor="@color/colorAccent"
android:textSize="9.25sp" />

<TextView
android:id="@+id/note_shb3"
android:layout_width="70dp"
android:layout_height="13.25dp"
android:layout_below="@id/note_title_text_bottom"
android:layout_margin="0dp"
android:layout_toRightOf="@id/note_shb2"
android:background="@mipmap/note_shb3"
android:fontFamily="@font/digital_7_mono"
android:gravity="center"
android:text="Bluetooth"
android:textColor="@color/colorAccent"
android:textSize="9.25sp" />

<ImageView
android:id="@+id/note_button_top"
android:layout_width="207dp"
android:layout_height="18dp"
android:layout_below="@id/note_shb1"
android:layout_toRightOf="@id/note_picture_right_bottom"
android:clickable="true"
android:scaleType="centerInside"
android:src="@mipmap/note_button_top" />

<ImageView
android:id="@+id/note_shuffle"
android:layout_width="34.25dp"
android:layout_height="35dp"
android:layout_below="@id/note_button_top"
android:layout_toRightOf="@id/note_picture_right_bottom"
android:clickable="true"
android:src="@drawable/note_shuffle_selector" />

<ImageView
android:id="@+id/note_back"
android:layout_width="34.25dp"
android:layout_height="35dp"
android:layout_below="@id/note_button_top"
android:layout_toRightOf="@id/note_shuffle"
android:clickable="true"
android:src="@drawable/note_back_selector" />

<ImageView
android:id="@+id/note_stop"
android:layout_width="34.25dp"
android:layout_height="35dp"
android:layout_below="@id/note_button_top"
android:layout_toRightOf="@id/note_back"
android:clickable="true"
android:src="@drawable/note_stop_selector" />

<ImageView
android:id="@+id/note_play"
android:layout_width="34.25dp"
android:layout_height="35dp"
android:layout_below="@id/note_button_top"
android:layout_toRightOf="@id/note_stop"
android:clickable="true"
android:src="@drawable/note_play_selector" />

<ImageView
android:id="@+id/note_next"
android:layout_width="34.25dp"
android:layout_height="35dp"
android:layout_below="@id/note_button_top"
android:layout_toRightOf="@id/note_play"
android:clickable="true"
android:src="@drawable/note_next_selector" />

<ImageView
android:id="@+id/note_hands"
android:layout_width="35.75dp"
android:layout_height="35dp"
android:layout_below="@id/note_button_top"
android:layout_toRightOf="@id/note_next"
android:clickable="true"
android:src="@drawable/note_hands_selector" />

<TextView
android:id="@+id/note_title"
android:layout_width="137dp"
android:layout_height="25.75dp"
android:layout_below="@id/note_title_text_top"
android:layout_margin="0dp"
android:layout_toRightOf="@id/note_picture_right_top"
android:background="@mipmap/note_title_text"
android:ellipsize="end"
android:fontFamily="@font/digital_7_mono"
android:gravity="center"
android:paddingStart="1dp"
android:paddingEnd="1dp"
android:singleLine="true"
android:text="@string/emergency_broadcast"
android:textColor="@color/colorAccent"
android:textSize="16sp" />

<ImageView
android:id="@+id/note_power"
android:layout_width="35.75dp"
android:layout_height="25.75dp"
android:layout_alignTop="@+id/note_title"
android:layout_toRightOf="@id/note_title"
android:clickable="true"
android:src="@drawable/note_power_selector" />

(edit: added code for notification builder) code to build notification: (编辑:为通知构建器添加了代码)用于构建通知的代码:

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
        builder.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
    }else{
        builder.setStyle(new NotificationCompat.BigPictureStyle());
    }

            builder
            .setSmallIcon(R.drawable.icon)
            .setContentTitle(description.getTitle())
            .setSubText(metadataCompat.getText(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE))
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setContentIntent(pContentIntent);



    return builder;

I'm out of ideas, what am I missing? 我没主意了,我想念什么?

ensure that you have placed the slices image in the same dpi. 确保您以相同的dpi放置切片图像。

1- its better to achieve this using the xml drawable background of parent layout and add left rectangle top left. 1-最好使用父布局的xml可绘制背景来实现此目的,并在左上角添加左矩形。

2- using android:scaleType="FIT_XY" to achieve this. 2-使用android:scaleType =“ FIT_XY”实现此目的。

https://developer.android.com/reference/android/widget/ImageView.ScaleType https://developer.android.com/reference/android/widget/ImageView.ScaleType

Ensure that width of the @id/note_title_text_bottom equals to the sum of note_title and note_power in all your layout files (for all the screen sizes). 确保@ id / note_title_text_bottom的宽度等于所有布局文件(对于所有屏幕尺寸)中note_title和note_power的总和。 Otherwise, something is not right with the @mipmap/note_title_text_bottom" for one of the densities. Anyway, it's better to use relative sizes and scale you drawables instead of using multiple layouts with absolute values, which is really hard to maintain and scale. 否则,@ mipmap / note_title_text_bottom“对于其中一种密度是不正确的。无论如何,最好使用相对大小和缩放可绘制对象,而不是使用具有绝对值的多个布局,这实际上很难维护和缩放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模拟器与设备上的 Android 布局 - Android layout on emulator vs device Android Studio,布局不会在模拟器上显示 - Android Studio, Layout Will Not Display on Emulator Android Studio在模拟器上的不同布局 - Android studio different layout on emulator Android 工作室模拟器(未经授权的设备) - Android studio Emulator ( device unauthorized) 通知显示在 android 仿真器中,但不在物理设备上 - Notification shows up in android emulator but not on physical device 您可以在 Android Studio 中的 Android Emulator 设备和 USB 连接的真实设备之间发送通知以使用数据库进行演示吗? - Can you send notification between Android Emulator device and USB connected real device in Android Studio for demonstration purpose with database? Android 布局似乎在设备和模拟器中被裁剪 - Android Layout seemed to be cropped on device and in emulator Android Studio - 与预览版和模拟器相比,物理设备上的布局元素大小不同 - Android Studio - Layout Elements differ in size on the physical device, compared to the preview and emulator Android Studio Firebase通知设备到带有主题的设备 - Android Studio Firebase Notification Device to Device with Topics 模拟器上的布局与android studio预览版不同 - layout is different on the emulator than android studio preview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM