我有以下代码:
llColors = (LinearLayout) findViewById(R.id.llColorSpect);
llColors.setOnTouchListener(llTouch);
width = llColors.getWidth();
height = llColors.getHeight();
Log.i("LAYOUT WIDTH", "width" +width); //shows 0
Log.i("LAYOUT HEIGHT", "height" +h); //shows the correct height
让我困惑的是为什么是LAYOUT WIDTH
0。在 XML 中,我将布局宽度设置为match_parent
,高度设置为wrap_content
。
如何获取Bitmap
下面正在解码的内容并填写宽度 fill_parent 以上的布局?我使用 LayoutParams 吗?
bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.palette2);
XML 代码是这样的:
<LinearLayout
android:id="@+id/llColorSpect"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/palette2"
android:layout_alignParentBottom="true" >
</LinearLayout>
我想要完成的是雷曼术语,采用布局并用背景图像填充它,并使用像素来获取 X 和 Y 坐标。