Android 从xml向LinearLayout添加行无效

Android 从xml向LinearLayout添加行无效,android,android-fragments,Android,Android Fragments,你好,我有一个线性布局: <ScrollView android:layout_below="@+id/layout_voto" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/contenutoRiga" a

你好,我有一个线性布局:

<ScrollView 
        android:layout_below="@+id/layout_voto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

</ScrollView>

问题是我看不到我的行。。谁能告诉我原因?

对此不太清楚,但您可能需要在正在膨胀的视图上显式设置LinearLayout.LayoutParams。不确定,但我认为布局充气器会忽略XML根元素中的布局参数。或者,当您对其进行充气时,您只需要将父视图传递给充气()方法(而不是null),这样它就知道要分配什么样的布局参数。如果您尝试添加行,则
LinearLayout
contenutoRiga的方向是水平的,而它应该是垂直的。您也可以尝试使用
表格布局
。我将方向更改为垂直,但没有更改。也许我必须将行添加到onCreateView中?如果我删除scrollview,我可以使用我的行!但是为什么呢?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content" >

<TextView
    android:id="@+id/nome_regola"
    android:gravity="center"
    android:layout_height="fill_parent"
    android:layout_width= "wrap_content"
    android:textSize="20sp"/> 

<ImageView
    android:id="@+id/immagineDettaglio"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/vero" />

<TextView
    android:id="@+id/voto_medio"
    android:gravity="center"
    android:layout_height="fill_parent"
    android:layout_width= "wrap_content"
    android:textSize="20sp"/> 
    public void aggDetRegole(DatiTest test) {

    TextView voto = (TextView) getActivity().findViewById(R.id.voto);
    voto.setText(Utilita.arrotondaVoto(test.getVoto()) +"");  
    LinearLayout contenitore = (LinearLayout) getActivity().findViewById(R.id.contenutoRiga);       
        for(.. v : ..){

            LinearLayout layout = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.riga_regole, null, false);
            TextView nome = (TextView) layout.findViewById(R.id.nome_regola);
            nome.setText(...);
            contenitore.addView(layout);
        }
    }