android - 对齐 AppBar 中的收藏按钮
问题描述
我创建了这个详细信息屏幕
我想将应用程序移动到最喜欢的按钮,例如
这是我的代码。
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/photo_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="350dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@android:color/transparent"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/detail_image_view"
app:layout_collapseMode="parallax"
android:src="@drawable/ic_broken_image"
android:contentDescription="@string/app_name"
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:layout_height="350dp" />
<android.support.v7.widget.Toolbar
android:id="@+id/detail_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name"
app:layout_collapseMode="pin"></android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/detail_title"
android:padding="12dp"
android:textSize="20sp"
android:layout_marginTop="12dp"
android:textStyle="bold"
android:textColor="@color/colorPrimaryDark"
android:text="Recent News"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:padding="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_clock" />
<TextView
android:layout_gravity="center_vertical"
android:id="@+id/detail_publish_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fav_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin"
android:elevation="@dimen/fab_elevation"
android:src="@drawable/ic_favorite_black_24dp"
app:pressedTranslationZ="12dp"
app:layout_anchor="@+id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
/>
我怎样才能做到这一点?
谢谢,
西奥。
解决方案
只需android:layout_gravity="bottom|end"
从你的删除FloatingActionButton
它就可以了
示例代码
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/photo_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="350dp"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="@android:color/transparent"
app:layout_collapseParallaxMultiplier="0.7"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:title=""
app:titleEnabled="false">
<ImageView
android:id="@+id/detail_image_view"
android:layout_width="match_parent"
android:layout_height="350dp"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop"
android:src="@drawable/kid_goku"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/detail_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/detail_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:padding="12dp"
android:text="Recent News"
android:textColor="@color/colorPrimaryDark"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="12dp">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_camera" />
<TextView
android:id="@+id/detail_publish_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fav_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin"
android:elevation="5dp"
android:src="@drawable/ic_camera"
app:layout_anchor="@+id/app_bar_layout"
app:layout_anchorGravity="bottom|end"
app:pressedTranslationZ="12dp" />
</android.support.design.widget.CoordinatorLayout>
输出
推荐阅读
- python - 如何修复 Metpy/mpcalc 错误:“InvalidSoundingError:压力不会单调下降。”
- node.js - 如何将 Wordpress 网站重定向到 Node-Angular 应用程序
- solana - 如何在 Windows 上安装 Solana?
- java - android中的SetMultiChoiceItems与动态列表数组
- excel - 我用什么分隔符来分隔这个单元格中的字符串
- reactjs - 当 url 更改但不替换 Next.js 中的整个页面时如何添加附加信息
- html - 制作下载按钮以在闪亮中创建和下载受密码保护的文件
- mongodb - 创建集合时如何创建唯一索引?还是在它创建之前?
- java - 我们可以将所有捕获从一个 try-catch-catch... 链转移到另一个函数以防止代码重复吗?
- php - 让我的用户 ID 将其传递给我的员工