2013-03-11 22 views
5

Quando provo ad aggiungere la mia vista personalizzata alla vista di scorrimento orizzontale non viene visualizzata. ma la stessa vista personalizzata è mostrata in altri layout come Layout relativo e lineare.La vista personalizzata non è mostrata nella vista orizzontale di scorrimento Non funziona

layout=new LinearLayout(this); 
     layout.setBackgroundColor(Color.YELLOW); 
     layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT)); 
     layout.setOrientation(LinearLayout.HORIZONTAL); 

     l = new PredicateLayout(this); 
//  l.sendtext(info); 
     for(int j=0;j<info.length;j++) 
     { 

      LinearLayout aa=new LinearLayout(this); 
      aa.setOrientation(LinearLayout.VERTICAL); 
      t = new TextView(this); 
       t.setText(info[j]); 
       t.setBackgroundColor(Color.GREEN); 
       t.setTextSize(i); 
       t.setWidth(screenwidth/2); 
       aa.addView(t); 
       l.addView(aa, new PredicateLayout.LayoutParams(0, 0)); 

     } 

     layout.addView(l); 
     scroll.addView(layout); 

mio aspetto XML come questo

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroll" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:orientation="horizontal" 
    > 

</HorizontalScrollView> 

provato anche come questo

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroll" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:orientation="horizontal" 
    > 

    <com.test.app.PredicateLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:id="@+id/predicate_layout" 
     > 

    </com.omnion.bible.PredicateLayout> 
</HorizontalScrollView> 

aspetto codice come

test=(PredicateLayout)findViewById(R.id.predicate_layout); 

for(int j=0;j<info.length;j++) 
     { 

      LinearLayout aa=new LinearLayout(this); 
      aa.setOrientation(LinearLayout.VERTICAL); 
      t = new TextView(this); 
       t.setText(info[j]); 
       t.setBackgroundColor(Color.GREEN); 
       t.setTextSize(i); 
       t.setWidth(screenwidth/2); 
       aa.addView(t); 
       test.addView(aa, new PredicateLayout.LayoutParams(0, 0)); 

     } 

Nessuno può aiutarmi. Grazie in anticipo.

+0

se si desidera creare visualizzazione personalizzata è necessario aggiungere la vista nel layout .. – Janmejoy

risposta

1

Metti la tua layout personalizzato come questo

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scroll" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:orientation="horizontal" 
    > 
<LinearLayout 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent"> 
    <com.test.app.PredicateLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:id="@+id/predicate_layout" 
     > 

    </com.omnion.bible.PredicateLayout> 
</LinearLayout> 
</HorizontalScrollView> 
Problemi correlati