Horizo​​ntalScrollView子项显示在外面

时间:2016-02-18 10:16:18

标签: android android-studio horizontalscrollview

放置Horizo​​ntalScrollView使其占用所有地平线空间。

滚动时,即使在Horizo​​ntalScrollView边界之外,填充顶部,边距顶部,包含Horizo​​ntalScrollView的卡片外部,在该边距和填充之上,子项也是可见的。
以编程方式添加子项,在垂直LinearLayout中添加ImageView和TextView。

我希望在超出ScrollView父级边界时屏蔽视图,但这种情况不会发生 这是创建子项的代码。

int pad = getResources().getDimensionPixelSize(R.dimen.element_margin);
int imageSize = Misc.dpToPx(30, this);
for(int i = 0; i < 6 ; i++){

    LinearLayout layout = new LinearLayout(this);

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( 3 * imageSize, LinearLayout.LayoutParams.WRAP_CONTENT);

    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setGravity(Gravity.CENTER_HORIZONTAL);
    layout.setPadding(pad, 0, pad,0);

    TintedIcon iv = new TintedIcon(layout.getContext());
    TextView tv = new TextView(layout.getContext());

    tv.setText("ארוחת בוקר");
    tv.setTextAppearance(this, android.R.style.TextAppearance_Small);
    tv.setTextColor(getResources().getColor(R.color.FontDark));

    //init image
    Drawable drawable = getResources().getDrawable(R.mipmap.breakfast);

    iv.setTintedDrawable(drawable, getResources().getColor(R.color.iconDark));
    iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
    iv.setAdjustViewBounds(true);


    layout.addView(iv, imageSize, imageSize);
    layout.addView(tv, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    features.addView(layout, lp);
}  

TintedIcon是一个视图,它使用一个函数扩展ImageView,该函数使用其drawable上的mutate()为图像提供色彩。

0 个答案:

没有答案