Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 以编程方式将视图添加到LinearLayout_Android - Fatal编程技术网

Android 以编程方式将视图添加到LinearLayout

Android 以编程方式将视图添加到LinearLayout,android,Android,我见过其他类似的问题,但没有人帮我。 我试图在LinearLayout中添加整个布局,这是我当前的代码: 主布局 这不起作用,不会向线性布局添加任何视图。有人知道吗?您从哪个活动方法调用视图生成代码?@jmuet来自另一个活动,这是一个静态方法。@Rafael Activity静态方法是有风险的,例如,当Activity layout完全没有膨胀时可以调用。我宁愿推荐一个侦听器模式,它可以帮助解耦您的两个Activities Define不起作用。logcat中会出现哪些异常?如果没有,请将日志

我见过其他类似的问题,但没有人帮我。 我试图在LinearLayout中添加整个布局,这是我当前的代码:

主布局


这不起作用,不会向线性布局添加任何视图。有人知道吗?

您从哪个活动方法调用视图生成代码?@jmuet来自另一个活动,这是一个静态方法。@Rafael Activity静态方法是有风险的,例如,当Activity layout完全没有膨胀时可以调用。我宁愿推荐一个侦听器模式,它可以帮助解耦您的两个Activities Define不起作用。logcat中会出现哪些异常?如果没有,请将日志记录到代码中,然后查看它给出了什么。@ChrisStratton alt尽管logcat没有显示任何内容,但LinearLayout上没有显示任何内容。
   <?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="70dp"
        android:clickable="false"
        android:focusable="false">

         <HorizontalScrollView
            android:layout_height="match_parent"
            android:layout_width="match_parent">

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

         </HorizontalScrollView>

        <ProgressBar 
            android:id="@+id/fragment_alertas_lista_peoples_progress"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"/>

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

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_below="@+id/image" />

        <ImageView
            android:id="@+id/image"
            android:layout_width="60dp"
            android:layout_centerHorizontal="true"
            android:layout_height="50dp"
            android:layout_margin="10dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" />

    </RelativeLayout>
for (Person person : listPeople) {

        View item = inflater.inflate(R.layout.item, null);
        ImageView img = (ImageView) item.findViewById(R.id.image);
        TextView name = (TextView) item.findViewById(R.id.name);

        img.setImageBitmap(person.getImage().getBitmap());
        name.setText(person.getName().toString());

        linearContent.addView(item);
}