Android UI Design: Pro. Xin Chen Email: Xinchen@zjnu - CN Mpi, Zjnu
Android UI Design: Pro. Xin Chen Email: Xinchen@zjnu - CN Mpi, Zjnu
Android UI Design
Layout elements:
Layout type
Widgets
Style
Theme
2.1 A layout file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/an
droid"
xmlns:tools="http://schemas.android.com/tools"
android: layout_width="match_parent"
android: layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeftt="true"
android:layout_alignParentTop="true"
android:layout_marginLeft=20dp"
android:layout_marginTop=50dp"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
Android Layout types
LinearLayout
RelativeLayout
TableLayout
GridLayout
FrameLayout
AbsoluteLayout
2.2 RelativeLayout
RelativeLayout is the default layout type for a new proje
ct.
Two cases:
Relative to the parent container
Relative to another widget
2.3 LinearLayout
In the LinearLayout, widgets are arranged on a ve
rtical or horizontal line.
android orientation =vertical | horizontal
2.4 TableLayout
android: columnCount=4
Look-out
GridLayout is a new feature in Android 4.0, so the minimum S
rsion in AndroidManifest.xml
<uses-sdk
android: minSdkVersion="14"
android: targetSdkVersion="17" />
2.3.5 FrameLayout
Each widget corresponds to a blank fr
ame
Only one widget/ frame is shown on t
* res/values /style.xml
<resources
xmlns:android="http://schemas.android.com/apk/res/and
roid">
<style name=textStyle">
<item name="android:textSize">16sp</item>
<item
name="android:textColor">#FF0000</item>
</style>
<style name=myTheme">
<item
name="android:background">#D9D9D9</item>
</style>
</resources>
2.4
<activity
android:name="com.example.hello.MainActivity"
android:label="@string/app_name"
android:theme="@style/yyTheme"
>
3. to use the text style in the layout file
<Button
style="@style/textStyle"
android:id="@+id/bt1"
android:text="OK"
android:layout_alignTop="@+id/tv1"
android:layout_marginTop="18dp"
/>
<Button
style="@style/textStyle"
android:id="@+id/bt2"
android:text="OK"
android:layout_below="@+id/bt1"
android:layout_marginTop="18dp"
/>
2.5 Debugging
2.6.1 Junit : Unit Testing
JUnit
Steps
1 config the Junit environment ( JUnit ) in AndroidManifest.xm
l
2 create the test class and method
3 running test
1. Configure in AndroidManifest
<uses-library android:name="android.test.runner"/>
</application>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.hello">
</instrumentation>
2.6 Debugging
2.6.1 LogCat
LogCat gives the log information for an Android pr
2. System.out.println(TextMessage)
2.6.2 Toast
Toasts methods
1. makeText(): to set the message
2. show(): to show the message
Toast toast = Toast.makeText(Context,Text,Time);
toast.show();
Toast.makeText(...,...",...).show();
Review
Different Layout Types along with widgets
Create and use new styles (themes)
Debug your android project by observing the Logcat
information or Toast texts.
Questions?