0

Öğeleri bir koordinatör düzeninde hizalamaya çalışıyorum. Ben alıyorum yukarıdaki kodunu uygulama hakkındaÖğe Düzeninde Düzgün Hizalama Öğeleri

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/main_content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

     <LinearLayout 
      android:id="@+id/appbar" 
      android:layout_width="match_parent" 
      app:layout_anchorGravity="top" 
      android:layout_height="256dp" 
      android:fitsSystemWindows="true" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      android:background="@color/colorPrimary"> 

      <LinearLayout 
       android:id="@+id/collapsing_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:fitsSystemWindows="true" 
       android:orientation="vertical"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/cheese_ipsum" /> 

       <RelativeLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 

        <Button 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="HAHAHA" /> 
       </RelativeLayout> 

      </LinearLayout> 

     </LinearLayout> 


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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:paddingTop="24dp"> 

      <LinearLayout 
       style="@style/Widget.CardContent" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Info" 
        android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/cheese_ipsum" /> 

      </LinearLayout> 


      <LinearLayout 
       style="@style/Widget.CardContent" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Friends" 
        android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/cheese_ipsum" /> 

      </LinearLayout> 


      <LinearLayout 
       style="@style/Widget.CardContent" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Related" 
        android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/cheese_ipsum" /> 

      </LinearLayout> 

     </LinearLayout> 

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

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="@dimen/fab_margin" 
     android:clickable="true" 
     android:src="@drawable/ic_discuss" 
     app:layout_anchor="@id/appbar" 
     app:layout_anchorGravity="bottom|right|end" /> 

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

: enter image description here

Ama düzeni düzgün hizalanması gibi bir şey istiyorum:

enter image description here

Bu kod aşağıdaki gibidir İlk linear layout'u AppBarLayout'a eklediğimde olur. Bu konuda gitmenin doğru yolu bu değil. Öğeleri bir coordinator layout içinde hizalamanın doğru yolu nedir?

cevap

0

benim cevap güncellenen bir AppBarLayout bunu yapmanın doğru yolu kullanarak bir android.support.design.widget.AppBarLayout

<android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     app:layout_anchorGravity="top" 
     android:layout_height="256dp" 
     android:fitsSystemWindows="true" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     android:background="@color/colorPrimary"> 

     <LinearLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/cheese_ipsum" /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="HAHAHA" /> 

     </LinearLayout> 

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

içine bu

<android.support.design.widget.CoordinatorLayout   
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 


    <LinearLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     app:layout_anchorGravity="top" 
     android:layout_height="256dp" 
     android:fitsSystemWindows="true" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     android:background="@color/colorPrimary"> 

     <LinearLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/cheese_ipsum" /> 

      <RelativeLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="HAHAHA" /> 
      </RelativeLayout> 

     </LinearLayout> 

    </LinearLayout> 

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



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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:paddingTop="24dp"> 

     <LinearLayout 
      style="@style/Widget.CardContent" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Info" 
       android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/cheese_ipsum" /> 

     </LinearLayout> 


     <LinearLayout 
      style="@style/Widget.CardContent" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Friends" 
       android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/cheese_ipsum" /> 

     </LinearLayout> 


     <LinearLayout 
      style="@style/Widget.CardContent" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Related" 
       android:textAppearance="@style/TextAppearance.AppCompat.Title" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/cheese_ipsum" /> 

     </LinearLayout> 

    </LinearLayout> 

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

<android.support.design.widget.FloatingActionButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="@dimen/fab_margin" 
    android:clickable="true" 
    android:src="@drawable/ic_book" 
    app:layout_anchor="@id/appbar" 
    app:layout_anchorGravity="bottom|right|end" /> 

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

bu ilk metin gösterimini kaldırır? Bu yanlış Düğmeyle ilk doğrusal düzeni kaldırdınız. o –

+0

<: layout_width = "wrap_content" android: RelativeLayout android layout_height = "wrap_content"> ' Bu göreli düzen, kodunuzda bulunmamaktadır. – Rgv

+0

'kaldırır –

0

uygulama çubuğu içinde görüşlerini içine alın işaretleyin. AppBarLayout ve kullanımı hakkında daha fazla bilgi edinmek için CheeseSquare (Google tarafından Malzeme Tasarım Destek Kitaplığı'nın doğru kullanımını sergileyen uygulama) için kaynak koduna bakın.

+0

Tam olarak, uygulama çubuğu düzenini kullanmadan 'doğrusal düzen' kullanmak istersem ne olur? Bu tam olarak benim sorum. Eğer 'uygulama çubuğu düzeni' kullanmıyorsam, kaydırma elde etmenin bir yolu var mı? –

İlgili konular