Height of notification incorrect “match_parent”

此生再无相见时 提交于 2019-12-22 10:36:42

问题


I try to make a custom view with this xml code:

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

and i run notification with this code:

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());
}

This is the result:

why "match_parent" does not use the full height of the notification ?

I want the red zone does the same height as the notification, without use "dip" unity. I use android 4.2.2. Thank you !


回答1:


Did you try using a RelativeLayout instead? And also play around with these attributes in the ImageView tag

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


来源:https://stackoverflow.com/questions/17052004/height-of-notification-incorrect-match-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!