开发者

Imageview positioning error

I am trying to set the position of an imageview in a relative layout in landscape mode.

I am using Displaymetrics function to get the screen widt and then calling setleft to set the left position of image view named mStone1.

mMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(mMetrics);

 mStone1.setLeft(mMetrics.widthPixels-5);

But My app is crashing with following erro开发者_如何学运维r:-

Could not find method android.widget.ImageView.setLeft, referenced from method com.example.Myapp.onCreate

VFY: unable to resolve virtual method 11: Landroid/widget/ImageView;.setLeft (I)V


This function is only available for API Level 11 and higher. So, unless you're writing for (and running the app in) Android 3.0, you can't use this function. Maybe try offsetLeftandRight http://developer.android.com/reference/android/view/View.html#offsetLeftAndRight(int)


You could also try the View.Layout(int, int, int, int); function I believe.

public void layout (int l, int t, int r, int b)

Since: API Level 1

Assign a size and position to a view and all of its descendants

This is the second phase of the layout mechanism. (The first is measuring). In this phase, each parent calls layout on all of its children to position them. This is typically done using the child measurements that were stored in the measure pass().

Derived classes should not override this method. Derived classes with children should override onLayout. In that method, they should call layout on each of their children.

Parameters:

l Left position, relative to parent
t Top position, relative to parent
r Right position, relative to parent
b Bottom position, relative to parent

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜