通知高度不正确“match_parent”

时间:2013-06-11 19:17:54

标签: android notifications height

我尝试使用此xml代码创建自定义视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF0000">
   <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@drawable/ic_launcher"/>
</LinearLayout>

我用这段代码运行通知:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main);
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_layout); 

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
    .setContent(remoteViews).setSmallIcon(R.drawable.ic_launcher);

    NotificationManager mNotificationManager = 
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    mNotificationManager.notify(20, mBuilder.build());
}

结果如下:

screenshot

为什么“match_parent”不使用通知的完整高度?

我希望红色区域与通知的高度相同,而不使用“dip”统一。我用android 4.2.2。谢谢!

1 个答案:

答案 0 :(得分:3)

您是否尝试使用RelativeLayout?并且还可以在ImageView标记中使用这些属性

android:scaleType="centerCrop"
android:adjustViewBounds="true"