A little tip for Android to show you how to center button on the screen, buttons in RelativeLayout and set the following properties in the right type Real.
1. Android Layout
File : res/layout/main.xml
Simple activity class, do nothing but display the above layout file.
android:layout_centerVertical="true"Following is a full example button center screen to demonstrate the use of above tip to center a button on screen.
android:layout_centerHorizontal="true"
1. Android Layout
File : res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>2. Activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="Button" />
</RelativeLayout>
Simple activity class, do nothing but display the above layout file.
public class HelloWorldActivity extends Activity {3. Demo on code android example
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
No comments:
Post a Comment