2017-01-04 105 views
0

我已經從android studio添加了一個leanback示例活動。該活動與下面的堆棧跟蹤崩潰。我沒有修改代碼,我發現默認添加的所有佈局確實都有layout_width和layout_height參數。Leanback示例活動崩潰

java.lang.RuntimeException: Binary XML file line #21: You must supply a layout_width attribute. 
    at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:608) 
    at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6485) 
    at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6654) 
    at android.widget.FrameLayout$LayoutParams.<init>(FrameLayout.java:741) 
    at android.support.v17.leanback.widget.BaseCardView$LayoutParams.<init>(BaseCardView.java:862) 
    at android.support.v17.leanback.widget.BaseCardView.generateLayoutParams(BaseCardView.java:817) 
    at android.support.v17.leanback.widget.BaseCardView.generateLayoutParams(BaseCardView.java:54) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:812) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:483) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:415) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
    at android.support.v17.leanback.widget.ImageCardView.buildImageCardView(ImageCardView.java:165) 
    at android.support.v17.leanback.widget.ImageCardView.<init>(ImageCardView.java:156) 
    at android.support.v17.leanback.widget.ImageCardView.<init>(ImageCardView.java:282) 
    at android.support.v17.leanback.widget.ImageCardView.<init>(ImageCardView.java:275) 
    at com.amazon.bueller.photos.activity.CardPresenter$1.<init>(CardPresenter.java:55) 
    at com.amazon.bueller.photos.activity.CardPresenter.onCreateViewHolder(CardPresenter.java:55) 
    at android.support.v17.leanback.widget.ItemBridgeAdapter.onCreateViewHolder(ItemBridgeAdapter.java:312) 
    at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6290) 
    at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5478) 
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5363) 
    at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5359) 
    at android.support.v17.leanback.widget.GridLayoutManager.measureScrapChild(GridLayoutManager.java:1211) 
    at android.support.v17.leanback.widget.GridLayoutManager.processRowSizeSecondary(GridLayoutManager.java:1277) 
    at android.support.v17.leanback.widget.GridLayoutManager.onMeasure(GridLayoutManager.java:1374) 
    at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3012) 
    at android.view.View.measure(View.java:17935) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5548) 
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) 
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) 
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) 
    at android.view.View.measure(View.java:17935) 
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5548) 
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) 
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) 
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) 
    at android.view.View.measure(View.java:17935) 
    at android.support.v17.leanback.widget.GridLayoutManager.measureChild(GridLayoutManager.java:1466) 
    at android.support.v17.leanback.widget.GridLayoutManager$2.createItem(GridLayoutManager.java:1556) 
    at android.support.v17.leanback.widget.SingleRow.appendVisibleItems(SingleRow.java:111) 
    at android.support.v17.leanback.widget.Grid.appendVisibleItems(Grid.java:371) 
    at android.support.v17.leanback.widget.GridLayoutManager.appendVisibleItems(GridLayoutManager.java:1749) 
    at android.support.v17.leanback.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:1973) 
    at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3506) 
    at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3254) 
    at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3767) 
    at android.view.View.layout(View.java:16046) 
                     at android.view.ViewGroup.layout 

回答

3

將'Theme.Leanback'添加爲活動樣式,錯誤將消失。

例子:

<activity android:name="com.sample.activity.DetailsActivity" 
       android:theme="@style/Theme.Leanback"/> 
+0

爲我工作。謝謝 – R00We