我正在为我的应用程序使用此循环菜单。 https://github.com/oguzbilgener/CircularFloatingActionMenu 这是工作。但是当我打开导航抽屉时。此菜单位于前面。如何使菜单返回导航抽屉。
如何将导航抽屉放在前面?
public class Home extends MainActivity implements OnClickListener
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
this.application = (Remtt) this.getApplication();
this.preferences = this.application.getPreferences();
super.onCreate(savedInstanceState);
this.checkOnCreate();
int redActionButtonSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_size);
int redActionButtonMargin = getResources().getDimensionPixelOffset(R.dimen.action_button_margin);
int redActionButtonContentSize = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_size);
int redActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.red_action_button_content_margin);
int redActionMenuRadius = getResources().getDimensionPixelSize(R.dimen.red_action_menu_radius);
int blueSubActionButtonSize = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_size);
int blueSubActionButtonContentMargin = getResources().getDimensionPixelSize(R.dimen.blue_sub_action_button_content_margin);
ImageView fabIconStar = new ImageView(this);
fabIconStar.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_headphones));
FloatingActionButton.LayoutParams starParams = new FloatingActionButton.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
starParams.setMargins(redActionButtonMargin, redActionButtonMargin, redActionButtonMargin, redActionButtonMargin);
fabIconStar.setLayoutParams(starParams);
FloatingActionButton.LayoutParams fabIconStarParams = new FloatingActionButton.LayoutParams(redActionButtonContentSize, redActionButtonContentSize);
fabIconStarParams.setMargins(redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin, redActionButtonContentMargin);
FloatingActionButton leftCenterButton = new FloatingActionButton.Builder(this).setContentView(fabIconStar, fabIconStarParams).setBackgroundDrawable(R.drawable.button_action_red_selector).setPosition(FloatingActionButton.POSITION_TOP_CENTER).setLayoutParams(starParams).build();
// Set up customized SubActionButtons for the right center menu
SubActionButton.Builder lCSubBuilder = new SubActionButton.Builder(this);
lCSubBuilder.setBackgroundDrawable(getResources().getDrawable(R.drawable.button_action_blue_selector));
FrameLayout.LayoutParams blueContentParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
blueContentParams.setMargins(blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin, blueSubActionButtonContentMargin);
lCSubBuilder.setLayoutParams(blueContentParams);
// Set custom layout params
FrameLayout.LayoutParams blueParams = new FrameLayout.LayoutParams(blueSubActionButtonSize, blueSubActionButtonSize);
lCSubBuilder.setLayoutParams(blueParams);
ImageView lcIcon1 = new ImageView(this);
ImageView lcIcon2 = new ImageView(this);
ImageView lcIcon3 = new ImageView(this);
ImageView lcIcon4 = new ImageView(this);
ImageView lcIcon5 = new ImageView(this);
ImageView lcIcon6 = new ImageView(this);
ImageView lcIcon7 = new ImageView(this);
ImageView lcIcon8 = new ImageView(this);
ImageView lcIcon9 = new ImageView(this);
lcIcon1.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon2.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon3.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon4.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon5.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_headphones));
lcIcon6.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon7.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon8.setImageDrawable(getResources().getDrawable(R.drawable.anim));
lcIcon9.setImageDrawable(getResources().getDrawable(R.drawable.anim));
// Build another menu with custom options
FloatingActionMenu leftCenterMenu = new FloatingActionMenu.Builder(this).addSubActionView(lCSubBuilder.setContentView(lcIcon1, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon2, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon3, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon4, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon5, blueContentParams).build())
.addSubActionView(lCSubBuilder.setContentView(lcIcon6, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon7, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon8, blueContentParams).build()).addSubActionView(lCSubBuilder.setContentView(lcIcon9, blueContentParams).build()).setRadius(redActionMenuRadius).setStartAngle(0).setEndAngle(360).attachTo(leftCenterButton).build();
}
}
}
答案 0 :(得分:0)
这与my answer here非常相似,只对FloatingActionButton
实例化进行了少量更改。
库代码假定按钮和菜单显示在活动内容视图的顶部,以及其中的所有内容。在FloatingActionButton
类中添加容器ViewGroup成员允许我们将子ViewGroup指定为父类。请注意,只有在菜单中使用FloatingActionButton
时,以下更改才有效。
FloatingActionButton
类的补充:
public class FloatingActionButton extends FrameLayout {
...
private ViewGroup containerView;
...
public FloatingActionButton(Activity activity,
LayoutParams layoutParams,
int theme,
Drawable backgroundDrawable,
int position,
View contentView,
FrameLayout.LayoutParams contentParams
// Note the addition of the following
// constructor parameter here
, ViewGroup containerView) {
...
setClickable(true);
// This line is new. The rest of the constructor is the same.
this.containerView = containerView;
attach(layoutParams);
}
...
public View getActivityContentView() {
if(containerView == null) {
return ((Activity)getContext())
.getWindow().getDecorView().findViewById(android.R.id.content);
} else {
return containerView;
}
}
public ViewGroup getContainerView() {
return containerView;
}
// The following setter is not strictly necessary, but may be of use
// if you want to toggle the Button's and Menu's z-order placement
public void setContainerView(ViewGroup containerView) {
this.containerView = containerView;
}
...
public static class Builder {
...
private ViewGroup containerView;
...
public Builder setContainerView(ViewGroup containerView) {
this.containerView = containerView;
return this;
}
public FloatingActionButton build() {
return new FloatingActionButton(activity,
layoutParams,
theme,
backgroundDrawable,
position,
contentView,
contentParams,
// New argument
containerView);
}
}
...
}
FloatingActionMenu
类的更改:
public class FloatingActionMenu {
...
public View getActivityContentView() {
if(mainActionView instanceof FloatingActionButton &&
((FloatingActionButton) mainActionView).getContainerView() != null) {
return ((FloatingActionButton) mainActionView).getContainerView();
} else {
return ((Activity)mainActionView.getContext())
.getWindow().getDecorView().findViewById(android.R.id.content);
}
}
...
}
然后,假设您的Activity的布局类似于:
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
...>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
...
</android.support.v4.widget.DrawerLayout>
在Home
活动中,您将构建并实例化leftCenterButton
,如下所示:
public class Home extends Activity implements OnClickListener {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
FrameLayout container = (FrameLayout) findViewById(R.id.container);
FloatingActionButton leftCenterButton = new FloatingActionButton.Builder(this)
.setContentView(fabIconStar, null)
.setBackgroundDrawable(R.drawable.ic_launcher)
.setPosition(FloatingActionButton.POSITION_TOP_CENTER)
.setLayoutParams(starParams)
// The new method call is added here
.setContainerView(container)
.build();
...
}
...
}