2017-02-10 2 views
0

Ich benutze ein Fragment in einem Viewpager und wenn ich es auf dem Emulator/Gerät ausführen, schrumpft es und bestimmte Textansichten verschwinden. Aber wenn ich die Ressource Layout des Fragments sehe separat dann sieht es ganz gutWarum schrumpft mein Layout im viewpager, sieht aber im separaten Layout-XML gut aus?

Dies ist, wie es aussieht, beim Laufen auf Emulator/Gerät: Aktivität enter image description here

Layout Aktivität

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/activity_landing_page" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="16dp" 
     android:paddingRight="16dp" 
     tools:context="com.thebitshoes.uocn.AdminHome" 
     android:orientation="vertical" 
     android:weightSum="3"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal"> 
     <ImageView 
      android:layout_width="326dp" 
      android:layout_height="wrap_content" 
      android:src="@mipmap/admin_bg_pic" 
      android:layout_gravity="center_horizontal" /> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@mipmap/profile_icon" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginBottom="23dp" /> 
    </RelativeLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="1" 
     android:background="#737D8C"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="#bfd919" 
      android:orientation="horizontal"> 
      <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="40" 
        android:background="#3c424c" 
        android:orientation="horizontal"> 
       <ImageView 
         android:id="@+id/message_icon" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:layout_weight="1" 
         android:src="@mipmap/message_icon_new" /> 
       <ImageView 
         android:id="@+id/notification_icon" 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical" 
         android:layout_weight="1" 
         android:src="@mipmap/notification_icon" /> 
      </LinearLayout> 
      <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="57.93" 
     android:background="#737d8c" 
     android:orientation="horizontal"> 
       <LinearLayout 
      android:paddingLeft="10dp" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
            > 
        <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:padding="5dp" 
       android:text="Welcome Back, John Doe !" 
       android:fontFamily="sans-serif-light" 
       android:textColor="#ffffff" 
       android:textSize="14sp" /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2.1" 
     android:orientation="vertical" 
     > 
     <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" /> 
     <android.support.design.widget.TabLayout 
     android:id="@+id/tab_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabBackground="@drawable/tab_color_selector" 
     app:tabTextColor="#3C424D" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 
     <android.support.v4.view.ViewPager 
      android:id="@+id/pager" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      android:layout_below="@+id/toolbar" /> 
    </RelativeLayout> 
</LinearLayout> 

unten ist das Layout des Fragments als getrennt betrachtet, Fragment XML

Layout Fragment in viewpager verwendet

<?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" 
    android:weightSum="1"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.18" 
     android:background="@drawable/cards" 
     android:orientation="horizontal"> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@mipmap/student_icon" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_marginLeft="16dp" 
      android:layout_marginStart="16dp"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="STUDENTS" 
       android:textStyle="bold" 
       android:textSize="18sp" /> 
      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="15dp" 
       android:orientation="vertical"> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="30 admissions in the past 10 days" /> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textStyle="bold" 
         android:text="Total" 
         android:layout_marginTop="6dp" /> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="100" 
         android:layout_marginTop="6dp" 
         android:layout_marginLeft="8dp" /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@android:color/darker_gray"/> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.18" 
     android:background="@drawable/cards" 
     android:orientation="horizontal" 
     > 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@mipmap/books_icon" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_marginLeft="16dp" 
      android:layout_marginStart="16dp"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="COURSES" 
       android:textStyle="bold" 
       android:textSize="18sp" /> 
      <LinearLayout 
       android:layout_width="252dp" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="15dp" 
       android:orientation="vertical"> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="12 course updates 2 months" /> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textStyle="bold" 
         android:text="Total" 
         android:layout_marginTop="6dp" /> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="100" 
         android:layout_marginTop="6dp" 
         android:layout_marginLeft="8dp" /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@android:color/darker_gray"/> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.18" 
     android:background="@drawable/cards" 
     android:orientation="horizontal" 
     > 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@mipmap/parent_icon" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_marginLeft="16dp" 
      android:layout_marginStart="16dp"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="PARENTS" 
       android:textStyle="bold" 

       android:textSize="18sp" /> 
      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="15dp" 
       android:orientation="vertical"> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="10 records added yesterday" /> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textStyle="bold" 
         android:text="Total" 
         android:layout_marginTop="6dp" /> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="200" 
         android:layout_marginTop="6dp" 
         android:layout_marginLeft="8dp" /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@android:color/darker_gray"/> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.18" 
     android:background="@drawable/cards" 
     android:orientation="horizontal" 
     > 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@mipmap/teacher_icon" /> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_marginLeft="16dp" 
      android:layout_marginStart="16dp"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="TEACHERS" 
       android:textStyle="bold" 
       android:textSize="18sp" /> 
      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="15dp" 
       android:orientation="vertical"> 
       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="10 active teachers" 
        android:textStyle="bold" 
        /> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textStyle="bold" 
         android:text="Total" 
         android:layout_marginTop="6dp" /> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="10" 
         android:layout_marginTop="6dp" 
         android:layout_marginLeft="8dp" /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 
    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="@android:color/darker_gray"/> 
</LinearLayout> 
+0

Ich sah ein 'LinearLayout' mit Gewicht' android: layout_weight = "57.93" in Ihrem Aktivitätslayout xml !! – shadygoneinsane

+0

hey there .. Ich habe versucht, es mit der GUI der Design-Ansicht des Layouts auszugleichen. Während es manuell, scheint es, dass der Wert irgendwie so viel erhöht wurde. – ThePercept

Antwort

0

Warum verwenden Sie Gewicht für Höhe jedes Kind Linearlayout? Wenn Sie das Fragment zu Ihrem Viewpager hinzufügen, wird die Größe basierend auf dem Gewichtsverhältnis angepasst. Es ist, weil der Viewpager nicht genug Höhe hat.

Wenn Sie Ihr Fragment innerhalb von viewpager genauso anzeigen möchten wie die unabhängige Ansicht, müssen Sie möglicherweise Scrollview oder Listview für das Fragment verwenden. Und Sie sollten alle Gewichtswerte entfernen und als wrap_content für jedes untergeordnete LinearLayout definieren.

+0

Zunächst fing ich an, das Layout zuerst zu machen und deshalb habe ich Gewichte hinzugefügt. War sich der Auswirkungen nicht bewusst. Danke für Ihren Vorschlag . Ich werde versuchen, es mit einer Bildlaufansicht wiederherzustellen. – ThePercept

+0

In diesem Fall wird Listenansicht eine bessere Option sein? – ThePercept

+0

Wenn Sie in Ordnung sind, kann es scrollbar sein, Scrollview ist einfach zu beheben, basierend auf Ihrem Code. Und wenn Sie bereit sind, in Zukunft weitere Artikel hinzuzufügen, würde ich ListView oder RecyclerView mit Adapter empfehlen. – steve

Verwandte Themen