private QueryItem createItem() {
   QueryItem item = new QueryItem(getActivity());
   MarginLayoutParams params =
       new MarginLayoutParams(Constant.WRAP_CONTENT, Constant.WRAP_CONTENT);
   params.topMargin = 20;
   item.setLayoutParams(params);
   return item;
 }
 public void restoreMarginLayoutParams(MarginLayoutParams params) {
   this.restoreLayoutParams(params);
   params.leftMargin = this.mPreservedParams.leftMargin;
   params.topMargin = this.mPreservedParams.topMargin;
   params.rightMargin = this.mPreservedParams.rightMargin;
   params.bottomMargin = this.mPreservedParams.bottomMargin;
   MarginLayoutParamsCompat.setMarginStart(
       params, MarginLayoutParamsCompat.getMarginStart(this.mPreservedParams));
   MarginLayoutParamsCompat.setMarginEnd(
       params, MarginLayoutParamsCompat.getMarginEnd(this.mPreservedParams));
 }
예제 #3
0
 /**
  * 设置View的顶部外边距(像素值)
  *
  * @param view
  * @return
  */
 public static boolean setMarginTop(View view, int marginTop) {
   MarginLayoutParams marginParams = null;
   try {
     marginParams = (MarginLayoutParams) view.getLayoutParams();
   } catch (ClassCastException e) {
     return false;
   }
   if (marginParams == null) return false;
   marginParams.topMargin = marginTop;
   view.setLayoutParams(marginParams);
   return true;
 }
예제 #4
0
 public void show(int touchX, int touchY) {
   this.mL = touchX - this.mRegistrationX;
   this.mT = touchY - this.mRegistrationY;
   this.mR = (touchX - this.mRegistrationX) + this.mWidth;
   this.mB = (touchY - this.mRegistrationY) + this.mHeight;
   this.mLayout.addView(this);
   MarginLayoutParams mp = (MarginLayoutParams) getLayoutParams();
   mp.leftMargin = this.mL;
   mp.topMargin = this.mT;
   mp.rightMargin = this.mR;
   mp.bottomMargin = this.mB;
   setLayoutParams(mp);
 }
예제 #5
0
  /** Initialize necessary items such as database(helper), lists etc. */
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.home_layout, container, false);

    // Retrieve databasehelper
    recipesHelper = ((MainActivity) this.getActivity()).getDatabaseHelper();

    // Initialize textview with introduction
    TextView tv = (TextView) v.findViewById(R.id.text);
    tv.setText(
        "Welcome to the Hotmeals App!"
            + '\n'
            + "You can search for recipes by pressing the search tab,"
            + '\n'
            + "or view recipes that you've marked as a favorite by pressing the favorites tab!"
            + '\n'
            + "Or if you like, browse the recipes you've recently viewed down below.");

    // Set top margins so that no overlap occurs
    MarginLayoutParams margins = (MarginLayoutParams) tv.getLayoutParams();
    margins.topMargin = ((MainActivity) this.getActivity()).getTabBarHeight();
    tv.setLayoutParams(margins);
    recipesReadableDatabase = recipesHelper.getReadableDatabase();

    // Init database list
    Cursor cursor = getRecentRecipes();
    recentRecipes = getRecipesFromCursor(cursor);
    cursor.close();

    // Done with database
    recipesReadableDatabase.close();

    // Populate list
    final ListView recentsList = (ListView) v.findViewById(R.id.recentsList);
    RecipeListViewAdapter adapter =
        new RecipeListViewAdapter(getActivity(), recipeArrayListToArray(recentRecipes));
    recentsList.setAdapter(adapter);

    // When recipe in list clicked, go to recipe
    recentsList.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Recipe recipe = (Recipe) recentsList.getItemAtPosition(position);
            goToRecipe(recipe);
          }
        });

    return v;
  }
예제 #6
0
 /**
  * 设置View的外边距(像素值)
  *
  * @param view
  * @param left
  * @param top
  * @param right
  * @param bottom
  * @return
  */
 public static boolean setMargin(View view, int left, int top, int right, int bottom) {
   MarginLayoutParams marginParams = null;
   try {
     marginParams = (MarginLayoutParams) view.getLayoutParams();
   } catch (ClassCastException e) {
     return false;
   }
   if (marginParams == null) return false;
   marginParams.leftMargin = left;
   marginParams.topMargin = top;
   marginParams.rightMargin = right;
   marginParams.bottomMargin = bottom;
   view.setLayoutParams(marginParams);
   return true;
 }
예제 #7
0
  private static void resetViewLayoutParams(View view, float scale) {

    if (view instanceof TextView) {
      resetTextSize((TextView) view, scale);
    }

    int pLeft = convertFloatToInt(view.getPaddingLeft() * scale);
    int pTop = convertFloatToInt(view.getPaddingTop() * scale);
    int pRight = convertFloatToInt(view.getPaddingRight() * scale);
    int pBottom = convertFloatToInt(view.getPaddingBottom() * scale);

    view.setPadding(pLeft, pTop, pRight, pBottom);

    LayoutParams params = view.getLayoutParams();
    if ("test_relayout".equals(view.getTag())) {
      Log.i("relayout", "test_relayout/" + params);
    }
    if (params == null) {
      return;
    }
    if (params.width > 0) {
      params.width = convertFloatToInt(params.width * scale);
    }
    if (params.height > 0) {
      params.height = convertFloatToInt(params.height * scale);
    }

    if (params instanceof MarginLayoutParams) {
      MarginLayoutParams mParams = (MarginLayoutParams) params;
      if (mParams.leftMargin > 0) {
        mParams.leftMargin = convertFloatToInt(mParams.leftMargin * scale);
      }
      if (mParams.rightMargin > 0) {
        mParams.rightMargin = convertFloatToInt(mParams.rightMargin * scale);
      }
      if (mParams.topMargin > 0) {
        mParams.topMargin = convertFloatToInt(mParams.topMargin * scale);
      }
      if (mParams.bottomMargin > 0) {
        mParams.bottomMargin = convertFloatToInt(mParams.bottomMargin * scale);
      }
    }
  }
    public void fillMarginLayoutParams(MarginLayoutParams params, int widthHint, int heightHint) {
      this.fillLayoutParams(params, widthHint, heightHint);
      this.mPreservedParams.leftMargin = params.leftMargin;
      this.mPreservedParams.topMargin = params.topMargin;
      this.mPreservedParams.rightMargin = params.rightMargin;
      this.mPreservedParams.bottomMargin = params.bottomMargin;
      MarginLayoutParamsCompat.setMarginStart(
          this.mPreservedParams, MarginLayoutParamsCompat.getMarginStart(params));
      MarginLayoutParamsCompat.setMarginEnd(
          this.mPreservedParams, MarginLayoutParamsCompat.getMarginEnd(params));
      if (this.leftMarginPercent >= 0.0F) {
        params.leftMargin = (int) ((float) widthHint * this.leftMarginPercent);
      }

      if (this.topMarginPercent >= 0.0F) {
        params.topMargin = (int) ((float) heightHint * this.topMarginPercent);
      }

      if (this.rightMarginPercent >= 0.0F) {
        params.rightMargin = (int) ((float) widthHint * this.rightMarginPercent);
      }

      if (this.bottomMarginPercent >= 0.0F) {
        params.bottomMargin = (int) ((float) heightHint * this.bottomMarginPercent);
      }

      if (this.startMarginPercent >= 0.0F) {
        MarginLayoutParamsCompat.setMarginStart(
            params, (int) ((float) widthHint * this.startMarginPercent));
      }

      if (this.endMarginPercent >= 0.0F) {
        MarginLayoutParamsCompat.setMarginEnd(
            params, (int) ((float) widthHint * this.endMarginPercent));
      }

      if (Log.isLoggable("PercentLayout", 3)) {
        Log.d(
            "PercentLayout",
            "after fillMarginLayoutParams: (" + params.width + ", " + params.height + ")");
      }
    }
 public void setContentY(final int contentY) {
   final MarginLayoutParams layoutParams = (MarginLayoutParams) getLayoutParams();
   layoutParams.topMargin = contentY;
   setLayoutParams(layoutParams);
 }