我正在尝试创建Android产品布局。页脚有两个按钮,它是固定按钮。当我滚动我的布局中附加的底部两个按钮时,你可以看到图像。请帮忙我该怎么办?
图片1
图片2
滚动后
XML
#!/usr/bin/perl
use LWP::UserAgent;
my $ou = new LWP::UserAgent;
my $url = "http://google.com";
my $source = $ou->get("$url")->decoded_content;
print "$source\n";
答案 0 :(得分:9)
您可以使用Relativelayout
作为外部布局并在其中保留CoordinatorLayout
,制作两个按钮android:layout_alignParentBottom="true"
<?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:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/groupbutton"
android:fitsSystemWindows="true"
tools:context="com.chivazo.chivazoandroid.activities.SingleProductActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="30dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/a"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_single_product" />
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:id="@+id/groupbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:weightSum="2">
<android.support.v7.widget.AppCompatButton
android:id="@+id/share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="share" />
<android.support.v7.widget.AppCompatButton
android:id="@+id/go_wishlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="go to Wishlist" />
</LinearLayout>
</RelativeLayout>
答案 1 :(得分:1)
只需将您的布局添加到xml中NestedScrollView下面的Coordinatorlayout中,然后在java中执行以下操作。
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) layoutToBeAnchored.getLayoutParams();
layoutParams.setAnchorId(R.id.layoutBelowWhichToBeAnchored);
layoutParams.anchorGravity = Gravity.CENTER;
layoutToBeAnchored.setLayoutParams(layoutParams);
希望这可以帮助你们。如有任何参考,您可以查看以下示例 - https://github.com/IsUncommon/Droidcon-India-2015
答案 2 :(得分:1)
The app:layout_anchor="@id/anchor_view"
and
app:layout_anchorGravity="bottom"
are the Important attributes here
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ProductDetailActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
.
.
.
<View
android:id="@+id/anchor_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
.
.
.
.
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_anchor="@id/anchor_view"
app:layout_anchorGravity="bottom">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
答案 3 :(得分:0)
如果您所包含的布局layout="@layout/content_single_product"
包含NestedScrollView
作为根视图容器。尝试为@+id/nestedView
添加一个ID,android:layout_height="match_parent"
,您必须添加具有相同按钮高度值的底部填充,并保持其余部分原样,并将包含以下两个按钮的底部线性布局中的android:layout_gravity="bottom"
替换为:
app:layout_anchor="@id/nestedView"
app:layout_anchorGravity="bottom"
答案 4 :(得分:0)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="center_vertical|start"
app:expandedTitleTextAppearance="@android:color/transparent"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:id="@+id/lay_image_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/browseCategories"
android:background="@color/white">
<FrameLayout
android:id="@+id/rel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<com.example.android_dev.ecm.View.ViewPagerCustomDuration
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="300dp" />
<com.example.android_dev.ecm.View.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/transparent"
android:padding="10dp" />
</FrameLayout>
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarSeller"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="56dp"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include
android:id="@+id/contentScroll"
layout="@layout/content_scroll_product_detail" />
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_gravity="center"
android:background="@drawable/shadow" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="@+id/addToCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/white"
android:text="Add To Cart"
android:textColor="@color/black"
android:textSize="16sp" />
<!--<Button
android:id="@+id/addToWishList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorAccent"
android:text="Add To Wishlist"
android:textColor="@color/white" />-->
<Button
android:id="@+id/buyNow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:text="Buy Now"
android:textColor="@color/white"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
content_scroll_product_detail.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:expandableTextView="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="com.example.android_dev.ecm.Helper.FixedScrollingViewBehaviour">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/productDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/productTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:textColor="@color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/productName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="2dp"
android:textSize="16sp" />
<RelativeLayout
android:id="@+id/priceLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/productDiscountPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/productPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/productDiscountPrice"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:textColor="@color/gray"
android:textSize="14sp" />
<LinearLayout
android:id="@+id/ratingProduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<TextView
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:padding="10dp"
android:text="3.2"
android:textColor="@color/colorAccent"
android:textSize="22sp" />
<RatingBar
android:id="@+id/star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/rating"
android:isIndicator="true"
android:numStars="1"
android:rating="1" />
</LinearLayout>
<LinearLayout
android:id="@+id/sold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/productPrice"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sold by : "
android:textColor="@color/gray"
android:textSize="14sp" />
<TextView
android:id="@+id/soldBy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textSize="14sp" />
</LinearLayout>
<TextView
android:id="@+id/orders"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/sold"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:text="Additional tax may apply charged at checkout"
android:textSize="14sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp"
android:weightSum="1">
<Button
android:id="@+id/share"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:background="@drawable/lay_border"
android:drawableLeft="@drawable/shareic"
android:drawablePadding="-20dp"
android:gravity="center"
android:paddingLeft="8dp"
android:text="Share"
android:textColor="@color/black" />
<Button
android:id="@+id/addToWishList"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:background="@drawable/lay_border"
android:drawableLeft="@drawable/pinic"
android:drawablePadding="-10dp"
android:gravity="center"
android:paddingLeft="8dp"
android:text="Add To Pinlist"
android:textColor="@color/black" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/ratingSeller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/productDetails">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp">
</RelativeLayout>
</android.support.v7.widget.CardView>
<TextView
android:id="@+id/outOfStock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ratingSeller"
android:background="@color/light_red"
android:gravity="center"
android:text="Sorry this product is out of stock."
android:textColor="@color/white"
android:textSize="22sp"
android:visibility="gone" />
<android.support.v7.widget.CardView
android:id="@+id/productVariants"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/outOfStock"
android:layout_marginTop="5dp">
<LinearLayout
android:id="@+id/addAttributesHere"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:id="@+id/saveButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/productVariants"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="2">
<Button
android:id="@+id/add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/black"
android:text="Add To Cart"
android:textColor="@color/white" />
<!-- <Button
android:id="@+id/save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorAccent"
android:text="Add To Wishlist"
android:textColor="@color/white" />-->
<Button
android:id="@+id/buyNow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorAccent"
android:text="Buy Now"
android:textColor="@color/white" />
</LinearLayout>
<android.support.v7.widget.CardView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/saveButtons"
android:layout_marginTop="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Description"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold" />
<com.ms.square.android.expandabletextview.ExpandableTextView
android:id="@+id/expand_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
expandableTextView:animDuration="200"
expandableTextView:maxCollapsedLines="2">
<TextView
android:id="@+id/expandable_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:textColor="@color/black"
android:textSize="14sp" />
<ImageButton
android:id="@id/expand_collapse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:background="@android:color/transparent"
android:padding="16dp" />
</com.ms.square.android.expandabletextview.ExpandableTextView>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/recommend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/description"
android:layout_marginTop="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">
<TextView
android:id="@+id/recommendHead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Recommendation"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/recommendText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/recommendHead"
android:padding="10dp"
android:text="Would you like to recommend this product?"
android:textColor="@color/gray"
android:textSize="14sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/recommendText"
android:layout_marginBottom="5dp"
android:background="@drawable/lay_border"
android:weightSum="2">
<Button
android:id="@+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:background="#deffffff"
android:text="Yes"
android:textColor="@color/colorPrimary"
android:textSize="18sp" />
<Button
android:id="@+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:background="#f7f5f5"
android:text="No"
android:textColor="@color/colorPrimary"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/productSellers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/recommend"
android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/addSellersHere"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>