<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>
Copy the code

To dynamically modify the height of the LinearLayout in your code, do something like this:

mallBoardLayout = findById(R.id.mall_board_layout);
ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) mallBoardLayout.getLayoutParams();
lp.topMargin = ScreenUtil.dip2px(80);
mallBoardLayout.setLayoutParams(lp);
Copy the code

That’s ok, because the parent of the LinearLayout is ConstraintLayout

If I write it like this:

LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mallBoardLayout.getLayoutParams();
lp.topMargin = ScreenUtil.dip2px(30);
mallBoardLayout.setLayoutParams(lp);
Copy the code

Will report an error!!