【发布时间】:2016-03-31 06:38:33
【问题描述】:
我正在尝试为通知构建自定义布局,但面临布局问题。图像显示在中间而不是左侧,文本不可见。尝试过 Liner 布局、文本样式和颜色等,但没有运气。布局中缺少什么?
Custome_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp" >
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp" />
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
style="Custom Notification Title" />
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/image"
android:layout_below="@id/title"
style="Custom Notification Text" />
</RelativeLayout>
Java 代码
private void sendNotification(String title, String msg, String type, String imageURl, String fullid, String alert_price, int count) {
WakeLocker.acquire(this);
//msg = msg+"Amit this is testing for long text";
long when = System.currentTimeMillis();
//count = count+5;
System.out.println(msg);
mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this).setSmallIcon(R.drawable.logo);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setImageViewResource(R.id.image, R.drawable.logo);
contentView.setTextViewText(R.id.title, "Amit notification");
contentView.setTextViewText(R.id.text, msg);
mBuilder.setContent(contentView);
Notification notification = mBuilder.build();
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" +R.raw.sound);
mNotificationManager.notify((int) when, notification);
//RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION, uri);
Ringtone ring = RingtoneManager.getRingtone(getApplicationContext(), uri);
ring.play();
((Vibrator) getApplicationContext().getSystemService( Context.VIBRATOR_SERVICE)).vibrate(1600);
WakeLocker.release();
}
【问题讨论】:
标签: android android-layout android-notifications