2016-04-09 51 views
2

我正在使用RecyclerView來表示一些數據。這是數據應如何顯示:RecyclerView中佈局的小部件顯示不正確

This is what I have

This is what I need

我爲沒有能夠上傳圖片抱歉。 我使用的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"> 





    <TextView 

     android:id="@+id/tvId" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="40dp" 
     android:layout_gravity="center_horizontal" 
     android:text="Some text" 

     /> 
    <TextView 
     android:layout_marginLeft="40dp" 
     android:id="@+id/tv1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="40dp" 
     android:text="Some text" 

    /> 
    <TextView 
     android:layout_marginLeft="40dp" 
     android:id="@+id/tv2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:text="Some text" 

     /> 
    <TextView 
     android:layout_marginLeft="40dp" 
     android:id="@+id/tv3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:text="Some text" 

     /> 
    <TextView 
     android:layout_gravity="center_horizontal" 
     android:id="@+id/price" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="30dp" 
     android:text="Some text" 

     /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Scan" 
     android:id="@+id/scanButton" 
     android:layout_marginTop="20dp" 
     android:layout_gravity="center_horizontal" 

     /> 

    <Button 
     android:id="@+id/submitButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Done" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="10dp" 
     /> 



</LinearLayout> 

不被編程改變佈局參數,什麼都可以沒有正確的在IDE預覽代表的原因是什麼?謝謝

+0

刪除'機器人:layout_gravity = 「CENTER_HORIZONTAL」' – VenomVendor

+0

變化...膨脹(佈局,NULL)膨脹(佈局,父母,假的),並分享您的代碼吹氣尤其是部分 –

+0

@BurakKarasoy它幫助,謝謝你,如果你想回答,我會很樂意接受它作爲正確的。 – bekabot

回答

0
change ... inflate(layout,null) to 
inflate (layout, parent, false) this because it needs parent's layoutparams 

父(充氣方法的第二個參數):

可選視圖,使其將所生成的分層結構的父(如果attachToRoot爲真

或者簡單地一個爲返回的層次結構的根提供一組LayoutParams值的對象(if attachToRoot is false。

http://developer.android.com/reference/android/view/LayoutInflater.html