繁体   English   中英

将视图膨胀到LinearLayout

[英]Inflate a view to a LinearLayout

如何将其他视图增加到linearlayout中? 最好先显示我的布局。

list.xml

        <FrameLayout >

            <ImageView/>

            <ProgressBar />

    </FrameLayout>      

    <TextView/>

    <TextView />

然后,main.xml

    <HorizontalScrollView
        android:id="@+id/hscrollview"
        android:layout_width="wrap_content"
        android:layout_height="40dip"
        android:layout_marginTop="50dip"
        android:background="#000000"
        android:scrollbars="none" >

        <LinearLayout
            android:id="@+id/linear_temp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="horizontal" >
        </LinearLayout>

    </HorizontalScrollView>

所以,我希望我的list.xml填充linearlayout 我的list.xml的数据来自我的json。 我花了很多时间将自己的实现更改为此。

我尝试这样做:(我首先忽略了图像)

//after parsing json and 
//and doing this..

        product = new ProductRowItem(imageUrl, sName, productId, desc, Integer.parseInt(imgHeight), Integer.parseInt(imgWidth), productOwnerId);
                                productItems.add(product);
//...
//by the way, product item is a pojo..


        for(ProductRowItem product : productItems){
            View productView = inflater.inflate(R.layout.product_list_layout, null);
            holder = new ViewHolder();
            holder.txtProductName = (TextView) productView.findViewById(R.id.product_name);
            holder.txtProductDesc = (TextView) productView.findViewById(R.id.product_desc);

            productView.setTag(holder);

            holder.txtProductName.setText(product.getProductName());
            holder.txtProductDesc.setText(product.getProductDesc());
        }

什么也没显示。关于充气到linearlayout的任何想法都将受到赞赏。 在此先感谢您。此外,我已经使用过Horizo​​ntalListView 我有一个原因,为什么我不会使用它。 并不是很糟糕,但是我无法覆盖,也没有overscrollBy方法

您可以为视图充气,但是不会在主视图中或在主视图中显示的组视图中添加创建的“ productView”!

您的通货膨胀是正确的(如果持有人是正确的)

在这种情况下,holder是没有用的,因为通常不会再为布局增加膨胀,而只会填充分配的视图。

在您的代码中:您总是初始化因视图而膨胀的容器!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM