Transfer from http://blog.csdn.net/hupei/article/details/52064946
Overview
Today, there is a group of friends asked how the image of the Android images protruding effect, there have been similar requirements, the whole project prompt box is a background, the background has a convex half picture, so with Layer-list wrote a background to achieve.
Thought casually painted a bit more ugly, probably this looks like, from which should not be difficult to see, there are three parts, the top is transparent, the bottom is colored value, the hexagonal star is convex out of the picture. Then let's do it. Create a new resource file, with the Layer-list property, with three item, the first item set the height to 30DP, the second item set top to 30DP, just a vertical layout, the third item contains a bitmap tag, The effect is to maintain the original size of the picture. Code
Layer-list background
- <? XML version= "1.0" encoding="Utf-8"?>
- <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item>
- <!--30DP Transparent --
- <shape>
- <size android:height="30DP" />
- <corners android:radius="10DP" />
- <solid android:color="@android: Color/transparent" />
- </shape>
- </Item>
- <!--offset 30dp-->
- <item android:top="30DP">
- <shape>
- <corners android:radius="10DP" />
- <solid android:color="@android: Color/white" />
- </shape>
- </Item>
- <!--use the bitmap label to keep the original size --
- <item>
- <bitmap
- android:gravity="Center_horizontal|top"
- android:src="@mipmap/ic_sync" />
- </Item>
- </layer-list>
Layout set root node background android:background= "@drawable/bg_money_dialog"
- <? XML version= "1.0" encoding="Utf-8"?><!--background bg_money_dialog-->
- <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/bg_money_dialog"
- android:orientation="vertical">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="Center_horizontal"
- android:hint="Please enter cash withdrawal amount" />
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="Center_horizontal"
- android:hint="Please enter your withdrawal password" />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="Center_horizontal"
- android:text="confirm" />
- </linearlayout>
Dialogfragment Code
- Public class Checkoutmoneydialog extends Dialogfragment {
- @Override
- Public Dialog Oncreatedialog (Bundle savedinstancestate) {
- Alertdialog.builder Builder = new Alertdialog.builder (Getactivity ());
- Layoutinflater inflater = getactivity (). Getlayoutinflater ();
- View view = Inflater.inflate (R.layout.fragment_checkout_money_dialog, null);
- Builder.setview (view);
- Dialog Dialog = Builder.create ();
- return dialog;
- }
- }
Run to see the effect
The effect is not good, may need to set EditText layout_margintop layout_margintop= "100DP" after the picture does not overlap on the EditText, can be top or no transparency effect, This reason is due to dialog background, the need for layout transparent, can dialog itself is also a background, we put dialog background transparent
[Java]View PlainCopy
- Dialog Dialog = Builder.create ();
- window window = Dialog.getwindow ();
- Window.setbackgrounddrawableresource (Android. R.color.transparent);
Android Image Bulge