<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/white">
<LinearLayout
android:id="@+id/mall_board_layout"
android:layout_width="match_parent"
android:layout_height="39dp"
android:layout_marginTop="8dp"
android:layout_marginLeft="14dp"
android:visibility="gone"
app:layout_constraintTop_toBottomOf="@+id/scroll_goods_container"
app:layout_goneMarginTop="12dp"
app:layout_constraintLeft_toLeftOf="parent"
android:orientation="horizontal"
android:gravity="start|center_vertical"
tools:visibility="visible">
<ImageView
android:id="@+id/mall_board_icon"
android:layout_width="13dp"
android:layout_height="13dp"/>
<TextView
android:id="@+id/mall_board_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13dp"
android:textColor="#E02E24"
tools:text="12123"
android:maxLines="1"
android:ellipsize="end"
android:layout_marginLeft="4dp"
android:includeFontPadding="false"
/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
复制代码
如果要在代码中,动态的修改LinearLayout的高度的话,需要这样操作:
mallBoardLayout = findById(R.id.mall_board_layout);
ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) mallBoardLayout.getLayoutParams();
lp.topMargin = ScreenUtil.dip2px(80);
mallBoardLayout.setLayoutParams(lp);
复制代码
这样子才可以,因为LinearLayout的父布局是ConstraintLayout
如果写成这样:
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mallBoardLayout.getLayoutParams();
lp.topMargin = ScreenUtil.dip2px(30);
mallBoardLayout.setLayoutParams(lp);
复制代码
就会报错!!!
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END