xml-drawable

XML Drawable not expanded to View size, or View not inheriting its parent's height correctly, on Android API < 11

微笑、不失礼 提交于 2019-11-29 15:44:15
Consider the following layout: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bg1" > <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg2" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <!-- some views here --> </LinearLayout> </FrameLayout> I'm using it to have bg2 on top of bg1 while bg2 remains completely independent, such that I

How to use a shape drawable together with an image?

我是研究僧i 提交于 2019-11-29 10:37:51
问题 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 drawable XML, but if I put the shape drawable as the background of my LinearLayout with android:background=@drawable/rounded_corner then I cannot assign any image to be used as a background. How can I get both a rounded corner with a background image in my LinearLayout? Any help would be appreciated. Thanks! 回答1: You could use LayerDrawable,

How to draw a dot circle inside a square drawable in android?

天涯浪子 提交于 2019-11-28 12:18:17
问题 I want a small dot inside a square button , this is what i have tried till now as answered by azizbekian: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <size android:width="100dp" android:height="100dp"/> <solid android:color="#38b0ef"/> </shape> </item> <item android:bottom="45dp" android:left="45dp" android:right="45dp" android:top="45dp"> <shape android:shape="oval"> <stroke android

how to add shadow effect on drawable in android

别来无恙 提交于 2019-11-28 10:47:02
I have created chat bubble with drawable which looks fine, now I want to add shadow effect below the drawable so it make 3d effect.I don't want to use 9-pitch image. I just want to know how i can add shadow effect on this drawable. my code is ----right_bubble_chat_drawable <?xml version="1.0" encoding="utf-8"?> <shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="15dp" /> <solid android:color="@color/chatrightbubbleColor" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> <size

XML Drawable not expanded to View size, or View not inheriting its parent's height correctly, on Android API < 11

坚强是说给别人听的谎言 提交于 2019-11-28 10:06:00
问题 Consider the following layout: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bg1" > <View android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg2" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <!-- some views here --> </LinearLayout> <

What should i use for better performance, nine-patch or drawable xml resource?

喜你入骨 提交于 2019-11-28 09:17:33
What is the best way to set background for some view? For example 2 variants of backround: background with gradient, rounded corners and border background with just one color and rounded corners So which of variants would be better, nine-patch or drawable xml resource? My guess is, NinePatch would be slightly faster in most cases. Here's what I found. GradientDrawable (the one used for rects in xml) uses this code to call through to Canvas which in turn uses native call leading to SkCanvas , SkDraw and eventually SkScan and SkBlitter . On the other hand, NinePatch 's draw() has almost zero

Create borders on a android view in drawable xml, on 3 sides?

为君一笑 提交于 2019-11-28 07:00:33
I want to make a drawable for my Android button, defined as drawable. I found I could set all the borders by using a rectangle, but I got kinda stuck when I wanted it on three sides. I want for example have either the top or the bottom open. Could anyone show me how to do this? Shubhayu Try doing this, though I saw it on some other post <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="#FFFFFF" /> <padding //android:bottom="10dp" Remove this to avoid seeing the bottom

BitmapFactory.decodeResource() returns null for shape defined in xml drawable

喜你入骨 提交于 2019-11-27 21:09:34
问题 I looked through multiple similar questions, although I haven't found proper answer on my query. I have a drawable, defined in shape.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="@color/bg_color" /> </shape> I want to convert it to Bitmap object in order to perform some operations, but BitmapFactory.decodeResource() returns null. This is how I'm doing it: Bitmap bmp = BitmapFactory

Android shape border with gradient

大城市里の小女人 提交于 2019-11-27 19:41:11
I want to create a border for a linearLayout. So I decide to create a shape. I want the border to have a gradient. The following is not doing it. It fills the rectangle and then creates a stroke. I don't want a filled rectangle, just the stroke. And I want to apply the gradient to the stroke. <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:angle="360" android:centerColor="#e95a22" android:endColor="#ff00b5" android:gradientRadius="360" android:startColor="#006386" android:type="sweep" />

Dotted line is actually not dotted when app is running on real Android device

試著忘記壹切 提交于 2019-11-27 15:35:20
问题 in my app I use XML defined vertical dotted line. <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="90" android:toDegrees="90"> <shape android:shape="line"> <stroke android:width="1dp" android:color="@color/light_gray" android:dashWidth="2dp" android:dashGap="4dp" /> </shape> When I am nitpicking my layout in Android Studio, the line is rendered properly dotted, as it should, but problem comes out when I run the app