I have to get this type of card design with semi-circle on both side of cardview along with shadows on both card view and semi-circles.
Thanks in advance.
I found a solution here that create a custom view called TicketView.
It provide various option to set the radius of the arc and divider options.
You can use it as custom view.
<com.vipulasri.ticketview.TicketView
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginTop="60dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="#+id/ticketView"
app:orientation="vertical"
app:scallopRadius="10dp"
app:showBorder="false"
app:scallopPositionPercent="50"
app:showDivider="true"
app:dividerType="dash"
app:ticketElevation="14dp"/>
It's not possible using Elevation API. A shadow is generated using view's ViewOutlineProvider with a convex path outlining the view. Your view is not convex, so you cannot make a proper ViewOutlineProvider, so you cannot get a nice, generated shadow that way.
The easiest way is to use a 9-patch with these cutouts drawn on it.
Related
I'm trying to create such a list of items in android, I am able to complete almost everything except the orange ribbon on the right top corner, I tried different methods to achieve this UI element but none of them works properly for me. I tried rotating a text view by 45ยบ with the ribbon image as background but the edges of the ribbon weren't perfect I also tried adding the ribbon as an image view and placed a text view on top of that but It was really difficult to place the ribbon and text view like this. So what is the easiest and most efficient way to achieve this?
Thanks in advance.
I don't think there is a native android component that supports such a feature. You can create a custom view making use of the path. Here is a great tutorial if you want to follow it.
Put this TextView into your FrameLayout/CardView:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff8f00"
android:textSize="16sp"
android:text="25% Off"
android:layout_gravity="end"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="-20dp"
android:rotation="45"
/>
To achieve best look, play with padding and margin attributes.
I have a CardView aligned to the top of the screen. Inside the CardView, there is an ImageView and I just want to adjust the height of the right-hand side of the CardView just like in the image below. Is this possible?
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_percent="1"
app:layout_constraintHeight_percent="0.4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:cardElevation="10dp"
app:cardCornerRadius="0dp">
<ImageView
android:id="#+id/bngCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="#drawable/explore2"
android:scaleType="centerCrop"/>
</androidx.cardview.widget.CardView>
Asides the radius, CardViews are usually rectangular in nature; therefore, this cannot be easily achieved with a CardView.
Best advice would be to create your own resource file. This way, you can define how exactly you want your view to look and still give it the properties you want (elevation, radius, etc).
To learn how to create a drawable resource file, check this tutorial out. You can also read up on the Android documentation on ShapeDrawables here.
CardView doesn't have the property to change on side height only. In this case, you must create a custom trapezoid shape instead, like this:
How to build trapezoid shape in xml android?
I have a RelativeLayout that inflates just fine. I would like to add a solid color rectangle spanning the width of the layout at the top. I tried putting the following into my xml:
<view android:id="#+id/top_alert"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_above="#+id/orders_gridview"
android:layout_alignParentTop="true"
android:background="#color/table_request_assistance"
android:visibility="visible"/>
Now, when I try to inflate my Layout I get a NullPointerException at LayoutInflater.createViewFromTag (line 715):
if (name.equals(TAG_1995)) {
name is set earlier thusly:
if (name.equals("view")) {
name = attrs.getAttributeValue(null, "class");
}
Evidently there is no "class" attribute. How do I add that? I can't find anything close in http://schemas.android.com/apk/res/android. Should I add it? Is this the standard way to do this? It seems like it should be the simplest thing in the world.
For the noobs here is some more general markup. This will print a 10-pixel high grey rectangle spanning the top of its parent view at the top.
<View android:id="#+id/rectangle_at_the_top"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_alignParentTop="true"
android:background="#DDDDDD"
android:visibility="visible"/>
Explanation:
This is the rectangle's id:
android:id="#+id/rectangle_at_the_top"
This says make the View as wide as the parent:
android:layout_width="match_parent"
Note you'll sometimes see "fill_parent". That has been deprecated in favor of "match_parent".
This says make the height 10 "ensity-independent pixels high:
android:layout_height="10dp"
What is a "density-independent pixel" you ask? I'm not 100% sure, but these guys know: What's the difference between px, dp, dip, and sp in Android?
This says align the rectangle with the top of the parent View:
android:layout_alignParentTop="true"
More accurately it makes the top edge of the View the same as the top edge of the parent. Want to put something at the bottom? Yup, you guessed it: use layout_alignParentTop.
This says set the background color to a grey-ish color:
android:background="#DDDDDD"
DDDDDD is a color value. You can find examples of other color values and how Google suggests to use them here: Google's Android Color Guide
Finally, this says to make this View visible:
android:visibility="visible"
This is mostly redundant as they are visible by default. Other options include "invisible" and "gone" which sound similar but are crucially different. For more info see this discussion: What is the difference between "invisible" and "gone?"
Classes are case sensitive - in this case, you are using the View class and therefore it needs to be exactly View in your XML.
On an iOS App I saw such a Button:
The same I would like to do in Android, how could I achieve this?
What I tried is the following code:
<Button
android:id="#+id/widget41"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Email1 testmail#gmail.com"
android:textStyle="bold" />
Looks something like that:
Well just a normal (ugly looking) Button. I have no idea, how I could style it like in iOS. Any suggestions or links would be appreciated!
The best solution would be to create your own custom view that behaves like the iOS counterpart (though, as other users have mentioned, Android does have it's own design guidelines, and the view that you are seeing is an iOS implementation that is designed for that platform).
If you look at the iOS image above (a copy of yours with some parts highlighted), I have split it up into sections.
You could use an Android ViewGroup like a LinearLayout to create the overall image, and give the LinearLayout a border or background (which can be a bitmap image of a rounded rectangle for example (See Android Nine Patch for an example of how to make this fit multiple screens).
Firstly, for the mail icon you would need a LeftAligned ImageView
with appropriate dimensions.
Next up we have a Bold TextView containing the text "Email1".
This is followed by another TextView which is blue and uses the
elipsize property (as defined in an Android XML layout) to create
"..." at the end once the text has reached the max width it can
consume. (Use android:ellipsize="end" in the XML)
Finally we have an indicator image, which again can be an ImageView
sized appropriately.
You could also achieve this with a RelativeLayout, which would allow you to RightAlign the indicator image, LeftAlign the mail icon, and allow the text to fill the space in between that it can get hold of.
Example of Nine Patch use for the background here
That is UITableView in iOS(just like ListView in android). It depends on the list item design you do it. There is no such Button Control in Android.
You should design your own button to looks like iOS one.
Android has it own design guidelines:
http://developer.android.com/design/patterns/pure-android.html
Well, as others have clearly mentioned there is no default Button in Android like this, and for your info neither is in iOS. Its all about the design. Anything is possible, in the end it all comes to how far are you willing to go to achieve it.
Below is a simple code, that will be close to your design.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:background="#drawable/text_background"
android:drawableLeft="#drawable/envelope"
android:drawablePadding="10dp"
android:drawableRight="#drawable/right_arrow"
android:ellipsize="end"
android:gravity="center_vertical"
android:text="#string/email" />
There can be other ways also, like that whole view could be a ViewGroup, either a LinearLayout or a RelativeLayout and there could be multiple TextViews and ImageViews inside that.
Here is a tutorial for creating stylized android buttons. You can round the corners and change the background colors to look like the buttons in ios.
Here is a similar question.
Hope this helps.
Pretty much what the title says. I'm wanting the user to have the choice to customize the boarder of a 9 drawable I have. Is something like that possible or do I need to use a different method? Right now, I think it won't work and it will mess up the 9 patch.
Can you post a picture of your 9-patch? It might be possible to extract parts of it to another type of drawable, then layer the customizable part (drawn with user defined color) under the fixed portions using a layer-list.
[Update] Based on the pic you posted, I'd trash the layer list idea, but we can still work something out. The idea would be to remove the colored border and internal dark background from the 9-patch entirely (fill that area in with the shadow color and opacity). Then nest 3 layouts in each other. The first would use the 9-patch as a background. The second would use the user-defined color as a background. The third would use your panel color as a background. The 9-patch would provide the proper margins to position the second (user-color) layout, and then you'd just add a layout_margin attribute to the second panel to position the inner most layout a few dps in.
<LinearLayout
android:id="#+id/PanelOuter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/shadow_nine_patch">
<LinearLayout
android:id="#+id/PanelUserBorder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/custom_border_width"
android:background="#color/dialog_border_color_default">
<LinearLayout
android:id="#+id/PanelContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/custom_dialog_content_margin"
android:background="#color/dialog_inner_color">
</LinearLayout>
</LinearLayout>
</LinearLayout>
Of course, you'd be responsible for finding the PanelUserBorder view in code and calling setBackgroundColor() with the proper user-defined color.
maybe you could tint it by putting a 50% transparent view overtop the button.
after thinking about it i thought maybe you could transform the color by bitmap:
How to change Bitmap image color in android?