Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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" >
- <TextView
- android:id="@+id/tv1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="20dp"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="50dp"
- android:text="aa"/>
- <TextView
- android:id="@+id/tv3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/tv2"
- android:layout_below="@+id/tv2"
- android:layout_marginTop="40dp"
- android:text="cc"
- android:textSize="20dp" />
- <TextView
- android:id="@+id/tv2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/tv1"
- android:layout_below="@+id/tv1"
- android:layout_marginTop="48dp"
- android:text="bb"
- android:textSize="20dp" />
- <TextView
- android:id="@+id/tv4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignRight="@+id/tv3"
- android:layout_below="@+id/tv3"
- android:layout_marginTop="38dp"
- android:text="dd"
- android:textSize="20dp" />
- </RelativeLayout>
- public class MainActivity extends Activity {
- TextView textViewDay, textViewMonth, textViewYear, textViewTime;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- textViewDay = (TextView) findViewById(R.id.tv1);
- textViewMonth = (TextView) findViewById(R.id.tv2);
- textViewYear = (TextView) findViewById(R.id.tv3);
- textViewTime = (TextView) findViewById(R.id.tv4);
- Time today = new Time(Time.getCurrentTimezone());
- today.setToNow();
- textViewDay.setText("Date " + today.monthDay + "");
- textViewMonth.setText("Month " + today.month + ""); // Month (0-11)
- textViewYear.setText("Year " + today.year + ""); // Year
- textViewTime.setText("Time " + today.format("%k:%M:%S"));
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement