2014-09-02 50 views
0

我正在開發一個功能,點擊一個按鈕時,新的視圖/按鈕從左到右添加,當空間用盡時,它會自動將按鈕添加到下一行。 只需跟進此link,集成後我無法看到我的視圖中的按鈕。浮動按鈕不顯示在視圖中Android

任何線索表示讚賞。

這是我的代碼。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/layout_filter" 
     android:orientation="horizontal"> 

    </LinearLayout> 

    <com.mypackage.predicatebuttonclass 
     android:id="@+id/predicate_layout" 
     android:layout_below="@id/layout_filter" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

</RelativeLayout> 

添加文本視圖動態

predicateLayout myLayout; 
     myLayout;= (PredicateLayout)mFilterLayout.findViewById(R.id.predicate_layout); 


      for (int i = 0; i < 10; i++) 
       { 
       TextView t = new TextView(ProductListingFragment.this.getActivity()); 
       t.setText("Hello"); 
       t.setBackgroundColor(Color.RED); 
       t.setSingleLine(true); 


       myLayout.addView(t, new PredicateLayout.LayoutParams(2, 0)); 
      } 

回答

1

你這條線設置補充視線的高度,以0:

new PredicateLayout.LayoutParams(2, 0) 

所以你不能看到它!因爲0寬度 height屬性的視圖將不會呈現。

+1

感謝您的回覆。發現flowLayout開源庫也很有幫助。 – karthik 2014-09-03 19:26:12

相關問題