this tutorial का उपयोग लचीला अंतरिक्ष पैटर्न (ढहने वाले टूलबार वाला एक) को लागू करने के लिए।एंड्रॉइड में लचीला स्थान
मैं लॉलीपॉप संपर्क गतिविधि है, जो शुरुआत में जब गतिविधि में प्रवेश, छवि हैडर का एक ही हिस्सा विचार के रूप में एक समान प्रभाव को प्राप्त करने की कोशिश कर रहा हूँ:
फिर , उपयोगकर्ता ताकि इसकी अधिक प्रकट करने के लिए में छवि के नीचे लेआउट नीचे स्क्रॉल कर सकते, जब तक यह अधिकतम तक पहुँच जाता है:
मेरे ऐप में, मैं इसे काम करने के लिए प्रबंधित नहीं कर सकता।
क्या होता है कि जब गतिविधि में प्रवेश, छवि हैडर प्रस्तुत किया जाता है यह ऊपर अधिकतम आकार, AppBarLayout का आकार है, बस लेआउट के रूप में, और लॉलीपॉप संपर्क गतिविधि, जहां यह केवल एक भाग से पता चलता में विपरीत है छवि का
इस कोड है कि AppBarLayout (मैं स्क्रीन की चौड़ाई चाहते अधिकतम ऊंचाई होने के लिए) की ऊंचाई को स्थापित करता है:
int widthPx = getResources().getDisplayMetrics().widthPixels;
AppBarLayout appbar = (AppBarLayout)findViewById(R.id.appbar);
appbar.setLayoutParams(new CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MATCH_PARENT, widthPx));
और यह कोड RecyclerView सेट है। scrollToPosition उपयोग करने की कोशिश, सोचा था कि यह ऊपर RecyclerView को देखते उठा होगा, लेकिन यह सब पर कोई प्रभाव नहीं है:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="0dp" // set programatically
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:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/header"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_profile_bottom_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<include
layout="@layout/navigation_view"/>
</android.support.v4.widget.DrawerLayout>
नोट::
mRecyclerView = (RecyclerView) findViewById(R.id.activity_profile_bottom_recyclerview);
mRecyclerView.setHasFixedSize(true);
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
// specify an adapter (see also next example)
if(mAdapter == null){
mAdapter = new ProfileAdapter(this, user, inEditMode);
mRecyclerView.setAdapter(mAdapter);
}
mRecyclerView.scrollToPosition(mAdapter.getItemCount() - 1); // itemCount is 4
यह लेआउट एक्सएमएल है मैं मैन्युअल रूप से नीचे स्क्रॉल तो , RecyclerView नीचे जाता है और छवि के अधिक खुलासा करता है, यह सिर्फ कोड के माध्यम से काम नहीं करेगा।
मुझे लगता है कि scrollToPosition समाधान नहीं है, क्या किसी को कोई विचार है?
और शायद enterAlwaysCollapsed ध्वज का उपयोग कर CoordinatorLayout में mentioned here के रूप में के बारे में सोचा minHeight साथ AppBar अनुभाग:
enterAlwaysCollapsed: आपके विचार एक minHeight की घोषणा की है और आप इस फ़्लैग का उपयोग हैं, तो आपके दृश्य केवल पर प्रवेश करेंगे अपनी न्यूनतम ऊंचाई (यानी, 'ध्वस्त'), स्क्रॉलिंग दृश्य इसके शीर्ष तक पहुंचने पर केवल अपनी पूर्ण ऊंचाई पर फिर से विस्तार कर रहा है।
तो, मैंने स्क्रॉल सेट किया है। EnterAlways मेरे टूलबार में मिनी ध्वज और मेरे RecyclerView में minHeight, जो काम नहीं किया। तब मैंने मिनीहेइट को अन्य लेआउट जैसे ऐपबारलाउट में ले जाने की कोशिश की, कुछ भी काम नहीं किया। यह कभी-कभी पूरे दृश्य के बिना छवि को कम कर देता है।
http://stackoverflow.com/questions/31945667/set-initial-height-of-parallax-image-in-collapsingtoolbarlayout – tachyonflux
अन्य समाधान मौजूद नहीं हैं? @karaokyo –
धन्यवाद @karaokyo, यह वास्तव में काम किया। अभी भी यह पता लगाने की कोशिश कर रहे हैं कि क्या अन्य समाधान भी हैं। – Jjang