我有3个动作按钮。一个扫描按钮和(如果某些条件被触发)另外两个“minifab”。扫描按钮应位于bottom|end
位置,其他两个应位于其顶部。
我使用自动生成的CustomView Android Studio给了我。现在我想知道如何改变我工厂的位置。我不能使用填充选项。这是因为CustomView?
这是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".SlideMenu">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/exportbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_share"
android:cropToPadding="false" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/savebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_save"
android:cropToPadding="false" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/scanbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_menu_add"
android:visibility="visible" />
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:1)
我认为这段代码对你有用我已经将CoOrdinate布局改为RelativeLayout而且每个按钮都会一个在另一个上面,你仍然可以通过给它填充来设置它
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".SlideMenu">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/exportbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_share"
android:cropToPadding="false"
android:layout_above="@+id/savebutton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/savebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_save"
android:cropToPadding="false"
android:layout_above="@+id/scanbutton"
android:layout_alignLeft="@+id/scanbutton"
android:layout_alignStart="@+id/scanbutton" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/scanbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@android:drawable/ic_menu_add"
android:visibility="visible"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
答案 1 :(得分:0)
解决了它;)
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".SlideMenu">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:id="@+id/exportbutton"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@android:drawable/ic_menu_share"
android:layout_above="@+id/savebutton"
android:layout_alignStart="@+id/savebutton"
android:layout_marginBottom="10dp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/savebutton"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@android:drawable/ic_menu_save"
android:layout_above="@+id/scanbutton"
android:layout_alignEnd="@+id/scanbutton"
android:layout_marginBottom="10dp"
android:layout_marginRight="8dp" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/scanbutton"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom|end"
android:src="@android:drawable/ic_menu_add"
android:visibility="visible"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>