2016-09-05 3 views
1

Ich mache ein Layout mit CoordinatorLayout, AppBarLayout, CollapsingToolbarLayout mit Toolbar. und ich füge Fragmente mit drawerLayout und setTitle mit collapsingToolbarLayout.setTitle("title") hinzu. Aber einige Seiten funktionieren gut, einige funktionieren falsch.Android CollapsingToolbarLayout funktioniert falsch

Ich weiß nicht warum. Könnte mir jemand helfen?

EDIT:

fand ich, dass Fehler tritt auf, wenn Fragmente ersetzen mit CollapsingToolbarLayout kollabierte.

xml hier

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="192dp" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/toolbarLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:expandedTitleMarginEnd="64dp" 
     app:expandedTitleMarginStart="48dp" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:layout_collapseMode="pin" /> 

    </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" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

</android.support.v4.widget.NestedScrollView> 

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

okay

wrong

+1

Versuchen, indem 'android: fitsSystemWindows = "true"' auf 'AppBarLayout'. –

+0

Ich weiß nicht, wann "AppBarLayout" und "CollapsingToolbarLayout" wie folgt funktioniert. – myoungjin

+0

Ich habe festgestellt, dass wenn Fragmente ersetzt werden, wenn "CollapsingToolbarLayout" zusammenbrach. – myoungjin

Antwort

0

nie den Wert von appbarlayout fest einprogrammiert es für die Referenz wickelt Inhalt machen gerade den Blick unter XML-Code, die Ihnen

helfen würden,

>

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/transaparent_color"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingTop="?attr/actionBarSize"> 

      <include layout="@layout/myparallaxview" /> 
     </FrameLayout> 

     <include layout="@layout/toolbar" /> 

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

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/color_ffffff" 
     android:orientation="vertical"> 

     <android.support.v7.widget.AppCompatTextView 
      android:id="@+id/user_name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="@dimen/dimen_15" 
      android:text="Chine Owhaigi" 
      android:textColor="@color/edit_text_color" 
      android:textSize="@dimen/dimen_text_16" 
      app:decorTypefaceAsset="@string/robotoRegular" /> 

     <android.support.v7.widget.AppCompatTextView 
      android:id="@+id/user_contact_no" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="@dimen/dimen_5" 
      android:text="7080644084" 
      android:textColor="@color/rechcolor" 
      android:textSize="@dimen/dimen_text_16" 
      app:decorTypefaceAsset="@string/robotoRegular" /> 


     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/dimen_25"> 

      <RelativeLayout 
       android:layout_width="245dp" 
       android:layout_height="150dp" 
       android:layout_gravity="center"> 

       <android.support.v7.widget.AppCompatImageView 
        android:id="@+id/profile_card" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:src="@drawable/account_detail_card" /> 

       <android.support.v7.widget.AppCompatImageView 
        android:id="@+id/add_money_button" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:layout_alignParentRight="true" 
        android:src="@drawable/edit_account" /> 

      </RelativeLayout> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center|bottom" 
       android:layout_marginBottom="@dimen/dimen_40" 
       android:paddingRight="@dimen/dimen_20" 
       android:orientation="vertical"> 

       <android.support.v7.widget.AppCompatTextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:text="@string/ecashBalance" 
        android:textColor="@color/color_ffffff" 
        android:textSize="@dimen/dimen_text_13" 
        app:decorTypefaceAsset="@string/robotoRegular" /> 

       <android.support.v7.widget.AppCompatTextView 
        android:id="@+id/cash_balance_text" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:text="2000000" 
        android:textColor="@color/color_ffffff" 
        android:textSize="@dimen/dimen_text_33" 
        app:decorTypefaceAsset="@string/robotoMedium" /> 
      </LinearLayout> 
     </FrameLayout> 


     <android.support.v7.widget.AppCompatTextView 
      android:id="@+id/edit_saved_cards" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/dimen_60" 
      android:layout_marginTop="@dimen/dimen_30" 
      android:background="@color/color_f5f6f8" 
      android:gravity="center" 
      android:text="@string/saved_cards" 
      android:textColor="@color/edit_text_color" 
      android:textSize="@dimen/dimen_text_16" 
      app:decorTypefaceAsset="@string/robotoRegular" /> 

     <include layout="@layout/profile_seprator" /> 

     <android.support.v7.widget.AppCompatTextView 
      android:id="@+id/edit_pin" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/dimen_60" 
      android:background="@color/color_f5f6f8" 
      android:gravity="center" 
      android:text="@string/reset_mpin" 
      android:textColor="@color/edit_text_color" 
      android:textSize="@dimen/dimen_text_16" 
      app:decorTypefaceAsset="@string/robotoRegular" /> 

     <include layout="@layout/profile_seprator" /> 


     <android.support.v7.widget.AppCompatTextView 
      android:id="@+id/edit_profile" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/dimen_60" 
      android:background="@color/color_f5f6f8" 
      android:gravity="center" 
      android:text="@string/edit_profile" 
      android:textColor="@color/edit_text_color" 
      android:textSize="@dimen/dimen_text_16" 
      app:decorTypefaceAsset="@string/robotoRegular" /> 

     <include layout="@layout/profile_seprator" /> 

    </LinearLayout> 
</android.support.v4.widget.NestedScrollView> 

+0

danke für deinen Rat! – myoungjin

0

Wie pro Ihren Code, den ich dies getan haben, können Sie sich beziehen. es wird dir helfen.

MainActivity.java

public class MainActivity extends AppCompatActivity { 

    private CollapsingToolbarLayout collapsingToolbarLayout; 
    private android.support.v7.widget.Toolbar toolbar; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     initToolbar(); 
     initAllWidgets(); 

    } 
    private void initToolbar() { 
     toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

    } 
    private void initAllWidgets() { 

     //setting toolbar properties; 
     getSupportActionBar().setHomeButtonEnabled(true); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

     //setup root layout 

     collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbarLayout); 
     collapsingToolbarLayout.setTitle("Abdul Rizwan"); 

    } 
} 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="192dp" 
     > 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/toolbarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:expandedTitleMarginEnd="64dp" 

      app:expandedTitleTextAppearance="@style/CollapsableTitle" 
      app:titleTextColor="@color/colorAccent" 
      app:expandedTitleMarginStart="64dp" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_scrollFlags="scroll|exitUntilCollapsed" 
       app:layout_collapseMode="pin" /> 

     </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" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

    </android.support.v4.widget.NestedScrollView> 

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

style.xml

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

<style name="CollapsableTitle" parent="@android:style/TextAppearance"> 
    <item name="android:textColor">@color/colorAccent</item> 
    <item name="android:textSize">@dimen/collapsable_title_size</item> 

</style> 

<dimen name="collapsable_title_size">26dp</dimen> 

color.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="colorPrimary">#3F51B5</color> 
    <color name="colorPrimaryDark">#303F9F</color> 
    <color name="colorAccent">#FF4081</color> 
</resources> 

manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.my.myapplication"> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 
+0

Ich versuche es, aber es funktioniert auch falsch. – myoungjin

Verwandte Themen