【问题标题】:Android adding dynamic ImageViews to HorizontalScrollView does not workAndroid向Horizo​​ntalScrollView添加动态ImageViews不起作用
【发布时间】:2015-01-15 23:51:14
【问题描述】:

我在很长一段时间内都在拼命地尝试实现这一目标,但仍然无法实现。 我有一个 ListView,在我的适配器内部,我试图根据我的数据动态添加图像视图。但是,ScrollView 不会显示添加的图像。当我尝试 myLinearLayout.getChildCount() 时,它给出了正确的结果!!

我做错了什么?非常感谢任何帮助:)

<!-- ScrollView (This lies inside listView's child view) -->
<HorizontalScrollView
        android:id="@+id/card_txn_horizontal_scroll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left">

        <LinearLayout
            android:id="@+id/scroll_view_linear"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:background="@color/header_bg">
       </LinearLayout>
 </HorizontalScrollView>

LinearLayout sharedWithView = (LinearLayout) convertView.findViewById(R.id.scroll_view_linear);
for (User sharer : data.getSharerModelList()) {
       ImageView mImageView = (ImageView) mInflator.inflate(R.layout.photo, null);
       Picasso.with(mImageView.getContext())
          .load(expense.getPayeeModel().getProfilePicUrl())
          .centerCrop()
          .resize(QuickReturnUtils.dp2px(mImageView.getContext(), 38),
                                    QuickReturnUtils.dp2px(mImageView.getContext(), 38))
                            .placeholder(R.drawable.ic_launcher)
                            .error(android.R.drawable.stat_notify_error)
                            .into(mImageView);
                    sharedWithView.addView(mImageView);
                }

【问题讨论】:

    标签: android android-listview horizontalscrollview


    【解决方案1】:

    LinearLayout 中尝试android:layout_width="wrap_content"

    【讨论】:

    • 感谢@medhdj:将`android:layout_width="wrap_content"`应用于HorizontalScrollViewLinearLayout对我有用:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多