如何将背景图像的resizezable(滚动时)设置为AppBarLayout?

时间:2017-03-24 06:20:02

标签: android android-layout material-design

我想创建一些像这样的视图: 1  和 2

<?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:background="@android:color/background_light"
android:fitsSystemWindows="true"
>

<android.support.design.widget.AppBarLayout
    android:id="@+id/main.appbar"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true"
    android:background="@drawable/test_background"
    >
    <include layout="@layout/information_content"/>
</android.support.design.widget.AppBarLayout>


<android.support.v7.widget.RecyclerView
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:lineSpacingExtra="8dp"
    android:id="@+id/recycler_view_comments">

</android.support.v7.widget.RecyclerView>

</android.support.design.widget.CoordinatorLayout>

和这一个information_content.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="180dp">
<RelativeLayout
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView
        android:layout_alignParentTop="true"
        android:layout_height="wrap_content"
        android:layout_width="192dp"
        android:text="Бар Чукотка \n Da Gudda Club"
        android:lines="2"
        android:id="@+id/text_view_place_name"
        android:textColor="@android:color/white"
        android:textSize="20sp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        />
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@id/text_view_place_name"
        android:layout_margin="20dp"

        >
        <ImageView
            android:id="@+id/address_icon"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/location_pointer"
            />
        <TextView
            android:layout_marginLeft="10dp"
            android:text="Ул Ш.Калдаякова 69 "
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textSize="20dp"
            />
    </LinearLayout>
</RelativeLayout>

<TextView
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_alignParentRight="true"
    android:layout_margin="10dp"
    android:text="7.6"
    android:textSize="20sp"
    android:gravity="center"
    android:textColor="#fff"
    android:background="@drawable/button_rating"/>

</RelativeLayout>

我对回收站视图没有任何问题,我只是想为AppBarLayout视图创建app_bar_main.xml文件,任何人都可以帮助解决至少这些问题吗?如果它是如此多的工作只是给出解决主要问题的想法

1 个答案:

答案 0 :(得分:0)

我通过这种方式解决了这个问题:

final float SCALE_MINIMUM=0.0018f;
   // Log.d(LOG_TAG,"scale density: "+scale+" image height in pixels"+mainBackdrop.getWidth());
    appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
        @Override
        public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
            ImageView imageView = (ImageView) appBarLayout.findViewById(R.id.main_backdrop);


            imageView.setScaleY(1 + (verticalOffset * SCALE_MINIMUM));

        }
    });