【发布时间】:2017-06-12 13:34:46
【问题描述】:
我正在尝试将高程添加到 LinearLayout(在片段中)。在我的装有 Android Nougat 的设备上,一切都很好,但在 Marshmellow 或 Lollipop 上则完全没有阴影。可能是什么问题?
LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.main_ll_newproducts);
ll.setBackgroundColor(Color.rgb(50,50,50));
LinearLayout llProduct = new LinearLayout(getContext());
llProduct.setBackgroundResource(R.drawable.product_selection_background);
llProduct.setOrientation(LinearLayout.HORIZONTAL);
llProduct.setPadding(20,0,0,0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
llProduct.setElevation(8);
}
llProduct.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
//Layoutparams
LayoutParams layParam = (LayoutParams) ll.getLayoutParams();
layParam.setMargins(10,10,10,30);
layParam.width = LayoutParams.MATCH_PARENT;
layParam.height = LayoutParams.WRAP_CONTENT;
// /Layoutparams
llProduct.setLayoutParams(layParam);
之后,我添加了更多视图,例如 Textviews 和一个 ImageView,然后将此 LinearLayout 添加到其父级。
ll.addView(llProduct);
【问题讨论】:
标签: android view fragment android-linearlayout android-elevation