【问题标题】:Collapse tool bar layout is not working折叠工具栏布局不起作用
【发布时间】:2015-09-13 12:42:39
【问题描述】:

我正在尝试在具有视差效果的回收器中显示酒店图像和酒店房间类型。我想要具有回收器视图的可折叠图像。我明白了,但崩溃不起作用。我做错了什么。 请帮助我..关于这个... 我的代码在这里

<android.support.design.widget.CoordinatorLayout         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:fitsSystemWindows="true"
>

<android.support.v7.widget.RecyclerView
    android:id="@+id/hotelDetailsRecyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<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:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/hotelHeaderImage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            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/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />

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

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

我的java文件是

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hotel_details);
    Toolbar toolBar=(Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar(toolBar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    hotelHeaderImage=(ImageView)findViewById(R.id.hotelHeaderImage);
    mVolleySingleton=VolleySingleton.getsInstance(this);
    mImageLoader=mVolleySingleton.getmImageLoader();
    mRecyclerview=(RecyclerView)findViewById(R.id.hotelDetailsRecyclerView);
    mLinearLayoutManager=new LinearLayoutManager(this);
    mRecyclerview.setLayoutManager(mLinearLayoutManager);
    mRecyclerview.setItemAnimator(new DefaultItemAnimator());
    ViewCompat.setTransitionName(findViewById(R.id.app_bar_layout), "");
    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbarLayout.setTitle("YG");

}

请告诉我我做错了什么?

【问题讨论】:

    标签: android android-recyclerview android-support-library android-collapsingtoolbarlayout


    【解决方案1】:

    要使其可折叠,您不需要 java 代码,只需要 xml。我将hotelHeaderImagelayout_height 更改为match_parent,将app_bar_layoutlayout_height 更改为256dp(例如),它起作用了。

    【讨论】:

      猜你喜欢
      • 2015-08-14
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多