How to use a shape drawable together with an image?

后端 未结 2 482
醉话见心
醉话见心 2020-12-30 19:33

I have this difficulty to have both rounded corner and a background image in my LinearLayout.

I know I can achive the rounded corner by using the shape

相关标签:
2条回答
  • 2020-12-30 20:11

    for those who seeks a different answer

    in the xml

    <string-array name="ulke_isimleri">
        <item>kan</item>
        <item>kebapeli</item>
    </string-array>
    
    <array name="ulke_gorselleri">
        <item>@drawable/kan1</item>
        <item>@drawable/esyalar_kebap_adana</item>
    </array>
    

    in the oncreate or general

     String[] ulkeAdlari =getResources().getStringArray(R.array.ulke_isimleri);
     TypedArray ulkeGorselleri = getResources().obtainTypedArray(R.array.ulke_gorselleri);
    

    as a function

     @Override
        public Drawable getDrawable(int position) {
    
             Drawable[] drawable = new Drawable[] { 
                     ulkeGorseli.getDrawable(position   ) 
                     ,
                     new TextDrawable(ulkeAdlari[ position   ]  )
             };
            return new LayerDrawable(drawable);
        }
    
    0 讨论(0)
  • 2020-12-30 20:12

    You could use LayerDrawable, which could contain as many layers(shapes or images) as you need. You can create it either as resource or programmatically.

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/rounded_corners" android:id="@+id/rounded_corners"/>
        <item android:drawable="@drawable/additional_image" android:id="@+id/additional_image" />
    </layer-list>
    
    0 讨论(0)
提交回复
热议问题