2016-08-02 6 views
2

Ich brauche programmaticaly verschiedene Symbole in Layer-Liste gesetzt von @ + id/calendar_day_bottom_iconProgrammaticaly gesetzt Bitmap in Layer-Liste Android

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/calendar_date_today_bg"/> 

    <item android:id="@+id/calendar_day_bottom_icon" > 
     <bitmap 
      android:src="@drawable/ic_calendar_journal" 
      android:gravity="bottom|center" /> 
    </item> 
</layer-list> 

In Code nächste, was ich tun

LayerDrawable layerDrawable = (LayerDrawable) cellView.getBackground();   
BitmapDrawable drawable = (BitmapDrawable) getResources().getDrawable(R.drawable.ic_calendar_journal_reminder); 
layerDrawable.setDrawableByLayerId(R.id.calendar_day_bottom_icon, drawable); 

Aber Symbol fügt falsch.

Ich möchte diese: enter image description here

Aber es gibt: enter image description here

+0

Verwenden Sie unten statt unten | Mitte. – Andolasoft

+0

android: gravity = "bottom | centre" zu android: gravity = "bottom" –

+0

es funktioniert nicht: ((irgendwelche Ideen? –

Antwort

0

ich die Lösung mit einer anderen ziehbar Datei finden:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <bitmap 
      android:gravity="bottom" 
      android:src="@drawable/ic_calendar_journal" /> 
    </item> 
</layer-list> 

ziehbar

LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(context, R.drawable.calendar_layers); 

holen LayerDrawable, l ayer Element und setzen Sie es auf ein anderes LayerDrawable.

LayerDrawable cellLayerDrawable = (LayerDrawable) cellView.getBackground(); 
Drawable drawable = layerDrawable.getDrawable(0);      
cellLayerDrawable.setDrawableByLayerId(R.id.calendar_day_bottom_icon, drawable);