|
发表于 2011-10-22 17:26:01
|
显示全部楼层
Re:Q
代码如下: // drawable-hdpi/round_button.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#0099FF">
<padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp">
<corners android:radius="8dp">
<stroke android:width="3dp" android:color="#FF000000">
</stroke>
</corners></padding></solid></shape>
[/code]// drawable-hdpi/oval_button.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#0099FF">
<stroke android:width="4dp" android:color="#FF000000">
</stroke>
</solid></shape>
[/code]// layout/main.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" androidrientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF">
<tablelayout android:id="@+id/TableLayout01" android:layout_height="fill_parent" android:stretchcolumns="*" android:gravity="center_vertical" android:layout_width="wrap_content" android:paddingleft="30dp" android:paddingright="30dp">
<tablerow android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingtop="50dp">
<button android:id="@+id/btnRectangle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click Me" android:background="@drawable/round_button" android:textsize="25sp" android:layout_marginleft="100px" android:layout_marginright="100px" android:layout_marginbottom="5px" android:layout_margintop="5px" android:height="50dp" android:width="50dp"></button>
</tablerow>
<tablerow android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingtop="50dp">
<button android:id="@+id/btnOval" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click Me2" android:background="@drawable/oval_button" android:textsize="25sp" android:layout_marginleft="100px" android:layout_marginright="100px" android:layout_marginbottom="5px" android:layout_margintop="5px" android:height="50dp" android:width="50dp"></button>
</tablerow>
</tablelayout>
</linearlayout>
[/code]// main.java
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnRectangle = (Button) findViewById(R.id.btnRectangle);
btnRectangle.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
" You clicked Rectangular button", Toast.LENGTH_SHORT).show();
}
});
Button btnOval = (Button) findViewById(R.id.btnOval);
btnOval.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
" You clicked Oval button", Toast.LENGTH_SHORT).show();
}
});
}
}
[/code] |
|