[Android] The RapidFloatingActionButton framework is officially released. floatingactionbutton
The following content is original. You are welcome to reprint it.
From Daily Blog: http://www.cnblogs.com/tiantianbyconan/p/4474748.html
RapidFloatingActionButton
Google released the design language of MaterialDesign. FloatingActionButton is a part of it, but Google did not provide an official FloatingActionButton control. I tried it on the Internet, but I never found a suitable one, therefore, you have made yourself a good fit.
RapidFloatingActionButton (RFAB) is a quick implementation of Floating Action buttons.
Github address: https://github.com/wangjiegulu/RapidFloatingActionButton
Usage:
Dependency:
AndroidBucket (https://github.com/wangjiegulu/AndroidBucket): Basic Toolkit
AndroidInject (https://github.com/wangjiegulu/androidInject): Annotation framework
NineOldAndroids (https://github.com/JakeWharton/NineOldAndroids): Compatible with lower-version animation Frames
Activity_main.xml:
1 <com.wangjie.rapidfloatingactionbutton.RapidFloatingActionLayout 2 xmlns:rfal="http://schemas.android.com/apk/res-auto" 3 android:id="@+id/activity_main_rfal" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 rfal:rfal_frame_color="#ffffff" 7 rfal:rfal_frame_alpha="0.7" 8 > 9 <com.wangjie.rapidfloatingactionbutton.RapidFloatingActionButton10 xmlns:rfab="http://schemas.android.com/apk/res-auto"11 android:id="@+id/activity_main_rfab"12 android:layout_width="wrap_content"13 android:layout_height="wrap_content"14 android:layout_alignParentRight="true"15 android:layout_alignParentBottom="true"16 android:layout_marginRight="15dp"17 android:layout_marginBottom="15dp"18 android:padding="8dp"19 rfab:rfab_size="normal"20 rfab:rfab_drawable="@drawable/rfab__drawable_rfab_default"21 rfab:rfab_color_normal="#37474f"22 rfab:rfab_color_pressed="#263238"23 rfab:rfab_shadow_radius="7dp"24 rfab:rfab_shadow_color="#999999"25 rfab:rfab_shadow_dx="0dp"26 rfab:rfab_shadow_dy="5dp"27 />28 </com.wangjie.rapidfloatingactionbutton.RapidFloatingActionLayout>
Add the RFAB outermost layer<com.wangjie.rapidfloatingactionbutton.RapidFloatingActionLayout>
, Button usage<com.wangjie.rapidfloatingactionbutton.RapidFloatingActionButton>
Attribute explanation RapidFloatingActionLayout:
Rfal_frame_color: The color of the outermost cover layer when RFAB is expanded. The default value is pure white rfal_frame_alpha: transparency of the outermost cover layer when RFAB is expanded (0 ~ 1). The default value is 0.7.
RapidFloatingActionButton:
Rfab_size: The size of RFAB. Only two types of sizes are supported (Material Design specifications): normal: 56dp diameter mini: 40dp rfab_drawable: icon in the middle of RFAB, the default value is a "+" icon rfab_color_normal: the normal color of the RFAB background. The default value is white rfab_color_pressed: The color of the touch press status of the rfab background. The default color is "# dddddd" rfab_shadow_radius: the shadow radius of RFAB. The default value is 0, indicating that there is no shadow rfab_shadow_color: the shadow color of RFAB. The default value is transparent. If rfab_shadow_radius is 0, this attribute is invalid. rfab_shadow_dx: The X-axis offset of the RFAB shadow. The default value is 0 rfab_shadow_dy: the offset of the Shadow Y axis of RFAB. The default value is 0.
MainActivity:
1 @AILayout(R.layout.activity_main) 2 public class MainActivity extends AIActionBarActivity implements RapidFloatingActionContentLabelList.OnRapidFloatingActionContentListener { 3 4 @AIView(R.id.activity_main_rfal) 5 private RapidFloatingActionLayout rfaLayout; 6 @AIView(R.id.activity_main_rfab) 7 private RapidFloatingActionButton rfaBtn; 8 private RapidFloatingActionButtonHelper rfabHelper; 9 10 @Override11 protected void onCreate(Bundle savedInstanceState) {12 super.onCreate(savedInstanceState);13 14 RapidFloatingActionContentLabelList rfaContent = new RapidFloatingActionContentLabelList(context);15 rfaContent.setOnRapidFloatingActionContentListener(this);16 List<RFACLabelItem> items = new ArrayList<>();17 items.add(new RFACLabelItem<Integer>()18 .setLabel("Github: wangjiegulu")19 .setResId(R.drawable.ic_launcher)20 .setIconNormalColor(0xffd84315)21 .setIconPressedColor(0xffbf360c)22 .setWrapper(0)23 );24 items.add(new RFACLabelItem<Integer>()25 .setLabel("tiantian.china.2@gmail.com")26 .setResId(R.drawable.ic_launcher)27 .setIconNormalColor(0xff4e342e)28 .setIconPressedColor(0xff3e2723)29 .setWrapper(1)30 );31 items.add(new RFACLabelItem<Integer>()32 .setLabel("WangJie")33 .setResId(R.drawable.ic_launcher)34 .setIconNormalColor(0xff056f00)35 .setIconPressedColor(0xff0d5302)36 .setWrapper(2)37 );38 items.add(new RFACLabelItem<Integer>()39 .setLabel("Compose")40 .setResId(R.drawable.ic_launcher)41 .setIconNormalColor(0xff283593)42 .setIconPressedColor(0xff1a237e)43 .setWrapper(3)44 );45 rfaContent46 .setItems(items)47 .setIconShadowRadius(ABTextUtil.dip2px(context, 5))48 .setIconShadowColor(0xff999999)49 .setIconShadowDy(ABTextUtil.dip2px(context, 5))50 ;51 52 rfabHelper = new RapidFloatingActionButtonHelper(53 context,54 rfaLayout,55 rfaBtn,56 rfaContent57 ).build();58 59 }60 61 @Override62 public void onRFACItemLabelClick(int position, RFACLabelItem item) {63 Toast.makeText(getContext(), "clicked label: " + position, Toast.LENGTH_SHORT).show();64 rfabHelper.toggleContent();65 }66 67 @Override68 public void onRFACItemIconClick(int position, RFACLabelItem item) {69 Toast.makeText(getContext(), "clicked icon: " + position, Toast.LENGTH_SHORT).show();70 rfabHelper.toggleContent();71 }72 }
Except forRapidFloatingActionLayout
AndRapidFloatingActionButton
In additionRapidFloatingActionContent
To fill in and specify the content and form of RFAB.
Here we provide a quickRapidFloatingActionContent
Implementation solution:RapidFloatingActionContentLabelList
. You can add multiple items (RFACLabelItem, of course, it is not recommended to add too many items, resulting in more than one screen ), then set the color, icon, shadow, label background image, font size color, and even animation of each item.
Its effect can be referred to the effect of the top film or Google's Inbox.
In addition, you also need to useRapidFloatingActionButtonHelper
To combine all the scattered components.
About expansion:
If you do not like the defaultRapidFloatingActionContentLabelList
In theory, you can expand your content style. The method is inheritancecom.wangjie.rapidfloatingactionbutton.RapidFloatingActionContent
And then initialize the content layout and style, and callsetRootView(xxx);
Method. To add an animation, rewrite the following method:
public void onExpandAnimator(AnimatorSet animatorSet);public void onCollapseAnimator(AnimatorSet animatorSet);
Add the expected Animator to the animatorSet.
In addition, the author will occasionally add more extensions of RapidFloatingActionContent.
License
Copyright 2015 Wang JieLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.