我尝试使用以下 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());
}
这是结果:
为什么“match_parent”不使用通知的完整高度?
我希望红色区域与通知的高度相同,而不使用“dip”统一。我用的是安卓4.2.2。谢谢 !
您是否尝试使用RelativeLayout 来代替?还可以在 ImageView 标签中使用这些属性
android:scaleType="centerCrop"
android:adjustViewBounds="true"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)