【发布时间】:2013-04-16 15:05:35
【问题描述】:
以下是相关代码位:
<HorizontalScrollView
android:id="@+id/cards_scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:fillViewport="false" >
<TableRow
android:id="@+id/cards_container"
android:layout_width="wrap_content"
android:layout_height="100dp" >
<ImageView
android:id="@+id/test_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="@dimen/cards_distance"
android:adjustViewBounds="true"
android:src="@drawable/card_back" />
</TableRow>
</HorizontalScrollView>
和
private void addCard(Drawable d) {
TableRow container = (TableRow) findViewById(R.id.cards_container);
ImageView card = new ImageView(this);
card.setAdjustViewBounds(true);
card.setPadding(R.dimen.zero, R.dimen.zero, R.dimen.cards_distance, R.dimen.zero);
TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
card.setLayoutParams(params);
card.setImageDrawable(d);
card.setVisibility(View.VISIBLE);
container.addView(card);
}
我确信我要添加的 Drawable 不为空,边界设置正确,alpha 设置为 255,并且适合。我已经通过将它应用到 test_card 而不是尝试添加新的 ImageViews 来测试它,这非常有效。
这里有什么我遗漏的吗?
【问题讨论】:
-
将 youractivty.this 传递给上下文
-
@edwin 方法无论如何都是顶级的,但我想通过 [Activity].this 是很好的风格。就我而言,没有任何改善。
标签: java android imageview tablerow