2017-07-11 43 views
0

快速的問題。我使用了標籤活動。 所以我創建了片段佈局。然後我用getItem方法class SectionsPagerAdapterswitch .... case來允許在這些佈局之間滑動。片段佈局不對應於android studio中的設計

在設計上的問題。在AVD結果是從結果在IDE設計預覽不同的...下面是我的XML片段和截圖...

順便說一句,我用inflateronCreateView爲:return inflater.inflate(R.layout.tab_etudiant,container,false);

佈局XML

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

    <ImageView 
     android:src="@drawable/etudiants" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="4" 
     android:scaleType="centerCrop"/> 

    <Button 
     android:id="@+id/btnNouveauEtu" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:text="INSCRIRE" 
     android:layout_weight="1"/> 

    <Button 
     android:id="@+id/btnModifEtu" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:text="EDITER" 
     android:layout_weight="1"/> 

    <Button 
     android:id="@+id/btnListerEtu" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:text="LISTER" 
     android:layout_weight="1"/> 

</LinearLayout> 

enter image description here

參見在左畫面(在IDE)有3個按鈕(Incrire, Editer, Lister)。在右側(即在AVD中)第三個按鈕(Lister)被切斷

+1

的區別是什麼? – tyczj

+0

@tyczj請參閱左側有** 3 **按鈕。在右側(即在AVD中)第三個按鈕被切割 –

+0

看起來像模擬器有一個不同於你創建的視圖的DPI。一切看起來很正常 – tyczj

回答

0

我仍然不知道問題是什麼,但這裏是我做過什麼來規避它:

  • 我採用了android工作室標籤活動模板......這模板使用android.support.design.widget.CoordinatorLayout作爲基地佈局
  • 片段佈局
  • 我改變了基地佈局到android.support.constraint.ConstraintLayout
  • 之後,所有你guyz提供和建議的解決方案也是我原來的代碼工作完全

希望這有助於有人...

更新

我用

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent""> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

</android.support.constraint.ConstraintLayout> 

,而不是

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

<android.support.v4.view.ViewPager 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
</android.support.design.widget.CoordinatorLayout> 
+0

如果你發佈更新的XML。它可能會幫助其他人陷入同樣的​​問題。 – Sufian

+0

@Sufian ...嘿,很高興再次見到你。我加了我的xml –

0

我在quora上回復您;) 問題比我想象的更復雜。

我建議你使用百分比relativelayout。一旦你習慣了它,它解決了很多問題,你的應用程序將適合每個屏幕;)

+0

我發現了一些東西:標籤活動的主要佈局中有一個父視圖,名爲'android.support.design .widget.CoordinatorLayout'弄亂了東西(不知道如何使用它)。當我將它切換到'android.support.constraint.ConstraintLayout'時,包括你在內的所有上述技術都是多餘的......一切正常工作......所以問題是'CoordinatorLayout' vs'ConstraintLayout' –

0

你能明確設置android:weightSum屬性<LinearLayout> XML元素,看看是否有幫助?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:weightSum=7> 

其實設置android:weightSum不是強制性的,但我一直使用它是明確的。

此外,您是否嘗試用android:scaleType的各種值(CENTER_CROP,FIT_XY等)來查看是否有幫助。

+1

沒有改變任何東西。我發現了一些東西:在標籤活動的主佈局中有一個名爲'android.support.design.widget.CoordinatorLayout'的父視圖弄亂了東西(不知道如何使用它)。當我將它切換到'android.support.constraint.ConstraintLayout'時,包括你在內的所有上述技術都是多餘的......一切都完美無缺......所以問題是'CoordinatorLayout' vs'ConstraintLayout' –