我是Android新手。在这里画一个矩形。添加按钮Android:添加按钮和矩形布局
public class DrawView extends View
{
Paint paint = new Paint();
public DrawView(Context context)
{
super(context);
}
@Override
public void onDraw(Canvas canvas)
{
paint.setColor(Color.BLACK);
canvas.drawRect(30f, 30f, 80f, 80f, paint);
}
}
我的XML代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="90dp"
android:layout_toRightOf="@+id/textView1"
android:text="Button" />
</RelativeLayout>
我有两个疑问。
1)我想要在应用程序顶部的矩形和底部的按钮。我应该怎么做?
2)后来我想改变矩形的颜色。我应该如何获得矩形来更改属性?
'android:layout_alignParentTop“true”'为矩形,而http://developer.android.com/training/custom-views/create-view.html为color属性。 – Simon