This post is also part of the Android series. Here we see a way to show license agreements on android UI with OK Cancel or Accept Reject buttons at the bottom. The license text ofcourse is scrollable and must occupy the left over space. We also throw in a check box for the user to disable the screen after reading/accepting the agreement.
The end UI looks like this
The layout Xml file is as follows. Notice the textview inside scroll view and the checkbox. There are suggestions on web to not use LinearLayout in a nested fashion. But, this one works quite well and is reasonably fast on a virtual device too.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/license_agree_scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true">
<TextView
android:id="@+id/license_agree_textview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="6dip" />
</ScrollView>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#393b3e"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/license_agree_prompt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="6dip"
android:text="@string/license_accept_prompt" />
<CheckBox
android:id="@+id/license_agree_check_noshow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/license_check_no_show_again" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#393b3e"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<Button
android:id="@+id/license_agree_reject"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center"
android:paddingBottom="6dip"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="6dip"
android:text="@string/license_agree_reject_btn" />
<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#393b3e"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/license_agree_accept"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center"
android:paddingBottom="6dip"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="6dip"
android:text="@string/license_agree_accept_btn" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#393b3e"
android:layout_alignParentBottom="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
The end UI looks like this
The layout Xml file is as follows. Notice the textview inside scroll view and the checkbox. There are suggestions on web to not use LinearLayout in a nested fashion. But, this one works quite well and is reasonably fast on a virtual device too.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/license_agree_scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true">
<TextView
android:id="@+id/license_agree_textview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="6dip" />
</ScrollView>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#393b3e"
android:layout_alignParentTop="true"/>
<TextView
android:id="@+id/license_agree_prompt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="6dip"
android:text="@string/license_accept_prompt" />
<CheckBox
android:id="@+id/license_agree_check_noshow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/license_check_no_show_again" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#393b3e"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<Button
android:id="@+id/license_agree_reject"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center"
android:paddingBottom="6dip"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="6dip"
android:text="@string/license_agree_reject_btn" />
<View
android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#393b3e"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/license_agree_accept"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center"
android:paddingBottom="6dip"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:paddingTop="6dip"
android:text="@string/license_agree_accept_btn" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#393b3e"
android:layout_alignParentBottom="true"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
No comments:
Post a Comment