I have a custom semicircle Liner Layout in which I want to add colored views , but these views do not match the custom shape(or stay within the bounds of the Liner Layout)
When I assigned custom shape to the views
custom shape
when I assign MATCH_PARENT to the views
match parent
I want the views to fill the inside of the Liner Layout while retaining the shape of it, is there any way this can be done?
You can't create a custom shape to a view. VIews are always rectangular. If you mean you have a custom background, that doesn't make the view group a custom shape, or effect the layout of views within the group. If you want to do that, you need to override onLayout (and possibly onMeasure) and layout the individual children with the bounds you expect them to be in. Do not be surprised if you get some ugly or non-functional results like this- views weren't made to be circular.
Related
I want to create a custom view
this view
and when add a view to XML I want to add static child view(textview,imageButtom and ...) into custom view like cardview and final view look like this picture
.how can we create a view?
You could start by extending an already defined layout like relative layout because creating a layout from scratch and implementing all methods in it is a little hard process. First thing came to my mind is adding a padding the custom layout for edge perspective effects so the layout don't place any view to this area. Then you can draw you perspective effect in onDispatchDraw() method. This method provide you with to draw canvas of the layout. In addition, using an drawable like nine patch as background makes things easier compared to custom drawing operation. In summary, you should give padding the layout to prevent overlapping with edge perspective. Then draw or set a background for the layout.
I'm creating a simple custom view. My view inherits from AppCompatImageButton with the goal of drawing some simple geometric shapes for my custom button and animating them.
If my XML view contains:
android:background="#color/transparent"
My view draws correctly inside a vertical LinearLayout, even though the android:background seems to otherwise do nothing. However, if I leave out android:background, the top and bottom displays an additional unwanted gap between the custom views.
The documentation says these two are "Related":
View.setBackgroundResource(int resid)
android:background
I've tried calling setBackgroundResource(R.color.transparent) in my Java initialization code, thinking this would do the same thing as XML android:background, but the unwanted padding won't go away. Here's a screenshot that shows the view without the android:background.
With android:background, the image fills the entire height not leaving the gap at the top and bottom.
How can I get my custom view to fill the entire drawing area without forcing an artificial android:background into the XML? The solution will also need to work if the programmer creates the custom view in Java without XML.
Thx.
I'm designing a layout for some listview items and I would like to draw a vertical dotted line to separate the content from some button on the right of the row, like in the example I attached. What is the best way to do it? And moreover: is there a way to obtain it by setting up some widget's property (something like setting up a css property for a border)?
Thanks
What is the best way to do it?
Put the widgets, including a new View for your divider, into a horizontal LinearLayout. Use a ShapeDrawable as the background for the View, where the ShapeDrawable defines your desired dash pattern.
Note that most UIs that have this sort of divider use a solid line.
is there a way to obtain it by setting up some widget's property
You can try to use android:drawableLeft and similar properties instead of the LinearLayout, if one of the widgets in this row is a TextView or inherits from it.
I have added a view to a layout which occupies a part of my screen. To this layout I want to add another layout which will be transparent. On this layout there should be only two lines which will scroll over the background layout. This I am doing so that my background layout is not invalidated and only the foreground is invalidated.
How can I add another layout which will be transparent?
Use FrameLayout as a parent layout and stack it up with as many layouts as you want. Thats one part of the answer. To make a layer (a layout in this case) transparent, set the alpha value in its background (a color) to 0. For instance android:background="#00777777" sets a background which is translucent with a dull gray.
You get the idea.
Use fram layout, which will allow you to add two views on each other.
I've got a ListActivity with a ListView in it. I need to draw a repeating image around the border ("on top of it (I guess after the listview is renderered))
How can I hook in my own drawing code for this?
You can use a FrameLayout to cause the ListView to overlap with a view that fills the entire screen. In this background view you could tile an image, or write your own custom View with your own drawing method.
There is no border property in ListView, as far as I know.
Instead you can put ListView into a FrameLayout and set the Background color of the FrameLayout.
Finally, set some padding to FrameLayout in order to create a border effect.
Hi
There is one way I have used, but that can be done in XML only.
android:background="#ffffff"
android:divider="#ffcccccc"
android:dividerHeight="1dip"/>
What I am doing is, putting listview in a LinearLayout. Background color of the list is different than that of layout. There is a margin set for layout. Hence the distance between list and layout will appear like a border for the listview.
Hope this helps.