2016-02-10 142 views
0

我有一个不显示特定布局的回收站视图。我知道布局是问题,因为我尝试了不同的布局,并且正在显示它们。我不会在控制台中发现错误的布局错误。RecyclerView不显示布局

这如下布局结构:

<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:background="#000" 
    android:layout_height="match_parent"> 

    <android.support.percent.PercentRelativeLayout 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:background="@color/border_color" 
     app:layout_heightPercent="30%"> 

    </android.support.percent.PercentRelativeLayout> 
</android.support.percent.PercentRelativeLayout> 

我看到它呈现正常,但可能是有点问题的。我希望每个回收商的物品都有30%的高度,这就是我使用app:layout_heightPercent="30%"的原因。如果我删除外部布局,则内部布局将占用所有空间。我怎样才能达到这个30%的高度,因为显然这是行不通的。

+0

为什么选d你有两个PercentRelativeLayout?如果你这样做,什么都不会显示 – hehe

+0

我在问题中解释了它。这不是我的整个布局。内部布局中有很多东西。我使用其中2个的唯一原因是因为如果我在预览时只使用了内部的一个,它不仅占用了所有空间的30% –

回答

0

试试这个: -

我已经设置高度100dp父PercentRelativeLayout。它为我工作。

<android.support.percent.PercentRelativeLayout 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:background="#000" 
     android:layout_height="100dp"> 

     <android.support.percent.PercentRelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#888888" 
      app:layout_heightPercent="30%"> 

     </android.support.percent.PercentRelativeLayout> 
    </android.support.percent.PercentRelativeLayout> 
0

对于有同样的问题的人,给一个ID,外布局,或任何布局的回收项目可能有outer

在你持有人将其定义:

outer = (PercentRelativeLayout) view.findViewById(R.id.outer); 

和里面你的onBindViewHolder以编程方式设定你的身高:

Display display = ((Activity)ctx).getWindowManager().getDefaultDisplay(); 
      Point size = new Point(); 
      display.getSize(size); 
      //int width = size.x; 
      int height = size.y; 

      ((MyRecyclerHolder) holder).outer.getLayoutParams().height = height/3;(or whatever ratio you want)