문제

I am showing 2 images in a layer-list this way. Following is layered_map.xml in drawable

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
           <item android:drawable="@drawable/bgimage" />
           <item android:id="@+id/marker"
                 android:drawable="@drawable/point"
                 android:left="660sp"
                 android:right="210sp"
                 android:top="375sp"
                 android:bottom="1125sp"
           />
    </layer-list>

Everything is fine. I get a big background image and a small layered image on top of it. Except now I would want to do what android:left, android:right, android:top, android:bottom do in xml, from Java This is what I have tried

      LayerDrawable layerDrawable = (LayerDrawable)getResources().getDrawable(R.drawable.layered_map);
      Drawable d = layerDrawable.findDrawableByLayerId(R.id.marker);
    d.setBounds(400, 300, 420, 320);
    //d.invalidateSelf();
    mImageView.setImageDrawable(layerDrawable);

But this does not work. I also read somewhere that it is not possible to set different bounds for different layers. I am also skeptical if what xml is doing in this is exactly done by setBounds. Any help will be really appreciated

Thank You

도움이 되었습니까?

해결책

yeah You can do it using setLayerInset (int index, int l, int t, int r, int b)

See here

and need help then ask :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top