2017-06-10 34 views
2

我的一项活动有3个片段,应该从上至下依次排列。适用于我的索尼Xperia Z3C(Android 6.0.1)手机,但在我的三星J1迷你(Android 5.1.1)上完美。第三/底部片段根本不显示。未在一台设备上显示Android片段

有一个空的空间,它可以去,我知道空的空间是空的 - 我设置了片段2和3的背景,2更改,但它下面仍然有一个空的空间。

我调整了代码,并放入了片段2的第二个副本,所以我假设它是片段本身的问题。

我知道创建了Fragment(它的onCreateView被调用,活动可以使用FragmentManager找到它),但它不会显示在我的一个手机上。

任何提示非常感谢。

这是片段(改了个名字,但没有别的...)

<FrameLayout 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" 
    tools:context="com.example.FragC"> 

    <GridLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:columnCount="4" 
     tools:background="@android:drawable/screen_background_dark"> 

     <Button 
      android:id="@+id/btnX" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_column="0" 
      android:layout_columnWeight="1" 
      android:layout_row="0" 
      android:onClick="scoreButtonClicked" 
      android:text="@string/xLab" /> 

     <!-- more buttons just the text, column and row changes --> 


    </GridLayout> 

</FrameLayout> 

这是活动

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activityLL" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.example.Activity1"> 

    <fragment 
     android:id="@+id/fragA" 
     android:name="com.example.FragA" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:layout="@layout/fragment_frag_a" /> 

    <fragment 
     android:id="@+id/fragB" 
     android:name="com.example.FragB" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:layout="@layout/fragment_fragb" /> 

    <fragment 
     android:id="@+id/fragC" 
     android:name="com.example.FragC" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:layout="@layout/fragmen_fragc" /> 

</LinearLayout> 

我只记得,我有这个活动的一道风景版本。它的顶层是一个水平线性布局。左列是包含片段1和2的垂直线性布局,然后片段3(又名不可见片段)应显示在右侧。它没有。空间在那里,但没有片段。

更新我将所有按钮从片段中取出,并用TextView(所有默认值通过GUI)替换它们,并显示出来。它会出现在按钮是令人困惑的三星...

我将按钮宽度从0dp更改为wrap_content,现在我看到按钮的第一列。我可以看到第二和第三栏,但如果我尝试添加第四栏,我可以看到的是第一栏。布局真的很奇怪...

回答

2

好的,所以我有我的答案:扔掉GridLayout并使用嵌套的LinearLayouts。

正如我所说的原始代码在1个设备上工作,但不是另一个。

帮助改变宽度。设置一个固定的宽度可以让我得到所有的按钮,但是在添加最后一个按钮时使用wrap_content,只剩下按钮1。

我找不出是什么问题,我发现大多数答案使用嵌套的LinearLayouts。我做了,他们工作!

+0

在我的5.0 Z3C column_weight似乎只适用于最后一项... –