Kho*_*fan 4 android android-layout android-cardview
这是代码
CardView.LayoutParams layoutParams = new CardView.LayoutParams(
CardView.LayoutParams.WRAP_CONTENT, CardView.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(100,100,100,100);
CardView cv = new CardView(this);
cv.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)
无论如何,从xml开始工作 -
android:layout_marginLeft="100dp"
Run Code Online (Sandbox Code Playgroud)
可能是什么原因?我错过了什么!
我需要提升卡片的保证金
谢谢
如果我理解正确,你试图避免裁剪高程阴影CardView.
而不是操纵边距,尝试将cardUseCompatPadding设置为true,如果要动态更改高程,则应在初始化时调用setMaxCardElevation(float)CardView.(两者都可以通过xml和编程方式设置).
设置最大高程CardView让它占用较大阴影的空间,但它也会为较低的高度添加此空间.
顺便说一句,如果你想LayoutParams为某个视图设置,你需要使用这些视图对应于视图的父视图.
示例:TextView内部有一个LinearLayout.
TextView textView = (TextView) findViewById(R.id.text_view);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)