2016-04-10 20 views
2

Android geliştirme konusunda yeniyim ve şu sorunla karşı karşıyayım. Bu benim ana faaliyet düzenidir:ViewPager, ekranın altına doğru uzanıyor

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar_main" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:elevation="4dp" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      app:layout_scrollFlags="scroll|enterAlways"> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:tabIndicatorColor="@color/white" 
       app:tabTextColor="@color/selected_text" 
       app:tabSelectedTextColor="@color/white"/> 

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

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/main_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

Ben bir fragman var ViewPager her sekme için, ve bu

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@color/colorPrimary" 
    android:id="@+id/linear_layout" 
    tools:context=".fragments.Reviews"> 

    <RatingBar 
     android:id="@+id/review_totalRating" 
     style="?android:attr/ratingBarStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:numStars="5" 
     android:stepSize=".5" 
     android:isIndicator="true" 
     android:progressTint="@color/golden" 
     android:layout_gravity="center" 
     android:paddingTop="10dp" 
     android:paddingBottom="5dp" /> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="8dp" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" 
     android:id="@+id/listView_reviews" /> 

</LinearLayout> 

Sonra benim ListView doldurmak bunlardan birinin düzenidir düzeni başka bir xml dosyasında tanımlanan öğeler. Benim sorunum ViewPager layout_height ile: şimdi match_parent olarak ayarlandı, ancak eleman ekranın alt kısmına uzanıyor, sonuçta ListView'ın son elemanı navigasyon düğmeleri tarafından kaplanıyor. Tasarım editöründe gördüğüm model bu (editör) Gezinme düğmelerinden önce elemanı nasıl durdurabilirim?

cevap

5

Bu sorunu da yaşadım. CoordinatorLayout'daki AppBarLayout davranışından kaynaklanmaktadır. Varsayılan olarak, bir şablondan bir proje oluşturduğunuzda, Toolbar'u gizleyerek düzeni ayarlar. Örneğinizi çalıştırabilir ve kontrol edebilirsiniz - sadece araç çubuğunu yukarı kaydırın ve gizlenir ve ViewPager yukarı doğru hareket eder ve ardından ekranın altına doğru yapışır.

Bazı durumlar için bir çözüm değildir, bu nedenle app:layout_scrollFlags özniteliğini Toolbar'dan kaldırarak bu davranışı devre dışı bırakabilirsiniz. Bundan sonra araç çubuğu görünmez hale gelir ve ViewPager kendi yüksekliğini doğru olarak hesaplar.

+0

Ben de aynı sorunla karşı karşıya ve öneri yardımcı oldu: Bu şimdi benim ana faaliyet düzenidir. Geridönüşümgörüşü yerine bir liste görünümü kullanılıyor mu? – dna

1

Bir LinearLayout kullanarak KoordinatorLayout'un tek alt öğesi olarak çözdüm, böylece her şey LinearLayout'un çocukları oluyor. Bana sadece basit bir çözüm olmak için geliyor, nihai bir çözüm değil, ama şimdi işe yarıyor.

<?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" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

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

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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar_main" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:elevation="4dp" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:tabIndicatorColor="@color/orange_050" 
       app:tabSelectedTextColor="@color/orange_050" 
       app:tabTextColor="@color/orange_050"/> 

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

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/main_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

</LinearLayout>