i具有可绘制背景的RelativeLayout
。如何将可绘制的背景转换为位图,以便我可以使用它来获得
View.OnTouchListener llTouch = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
x = (int)event.getX();
y = (int)event.getY();
int action = event.getAction();
int pixel = bitmap.getPixel((int)x,(int) y);
}
我的XML就是这样:
<RelativeLayout
android:id="@+id/rlColorSpect"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/palette2" >
<ImageView
android:id="@+id/ivSquare"
android:layout_width="@dimen/title_text_pad"
android:layout_height="@dimen/title_text_pad"
android:layout_alignParentBottom="true"
android:scaleType="fitXY"
android:src="@drawable/esquare" />
</RelativeLayout>
货车得到这样的布局尺寸:
RelativeLayout myRelativeLayout = (LinearLayout) findViewById(R.id.rlColorSpect);
int layoutWidth = myRelativeLayout.getWidth();
int layoutHeight = myRelativeLayout.getHeight();
并使用它调整位图大小。
其他选项是您在创建它之后为您的位图创建Relativelayout规则:这里
另一个想法是在该布局上放置一个不可见的想象,并用fill_parent将其覆盖整个布局并测量该图像以获取布局尺寸