【问题标题】:margins not set properlly in VIEW in android在android的VIEW中边距没有正确设置
【发布时间】:2015-07-17 19:16:19
【问题描述】:

边距未设置为动态创建的视图:-

 RelativeLayout.LayoutParams mDeleteBinLayoutParams = new RelativeLayout.LayoutParams(90, 90);

    mDeleteBinLayoutParams.setMargins(100, -20, 0, 10);

    final DeleteZone mDeleteZone = new DeleteZone(ThemeActivity.this);
    mDeleteZone.setImageResource(R.drawable.delete_zone);
    mDeleteZone.setId(-101);
    mDeleteZone.setLayoutParams(mDeleteBinLayoutParams);
    mDragLayer.addView(mDeleteZone);

【问题讨论】:

  • 为什么要设置负边距?
  • 我也检查了正边距,但它不起作用。
  • 你的mDragLayer是不是RelativeLayout
  • DragLayer 是用于拖放功能的绝对布局。
  • 那你为什么要设置RelativeLayoutParams

标签: android android-layout layoutparams


【解决方案1】:

我得到的解决方案:-

DragLayer.LayoutParams lp = new DragLayer.LayoutParams(
    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
    mProfile.getmCharsSize() + 50, 10);

【讨论】:

    【解决方案2】:
    RelativeLayout.LayoutParams mDeleteBinLayoutParams = new RelativeLayout.LayoutParams(90, 90);
    

    把它改成

     RelativeLayout.LayoutParams mDeleteBinLayoutParams = mDeleteZone.getLayoutParams();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多