SyntaxHighlighter JS

Showing posts with label android_ui_xml. Show all posts
Showing posts with label android_ui_xml. Show all posts

2013-03-07

Built-in Android ListView layouts: Part 2

See Part 1 here.
Android has several built-in ListView layouts that you can easily use without defining your own layout XML.

The source code needs cleanup and better documentation but it should give you an idea how to use the built-in layout.

android.R.layout.simple_list_item_activated_1
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<TextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:textAppearance=
  "?android:attr/textAppearanceListItemSmall"
  android:gravity="center_vertical"
  android:paddingStart=
  "?android:attr/listPreferredItemPaddingStart"
  android:paddingEnd=
  "?android:attr/listPreferredItemPaddingEnd"
  android:background=
  "?android:attr/activatedBackgroundIndicator"
  android:minHeight=
  "?android:attr/listPreferredItemHeightSmall"
/>


android.R.layout.simple_list_item_activated_2
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:paddingTop="2dip"
  android:paddingBottom="2dip"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background=
  "?android:attr/activatedBackgroundIndicator"
  android:minHeight=
  "?android:attr/listPreferredItemHeight"
  android:mode="twoLine"
>

  <TextView android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart=
    "?android:attr/listPreferredItemPaddingStart"
    android:layout_marginTop="6dip"
    android:textAppearance=
    "?android:attr/textAppearanceListItem"
  />

  <TextView android:id="@android:id/text2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@android:id/text1"
    android:layout_alignStart="@android:id/text1"
    android:textAppearance=
    "?android:attr/textAppearanceSmall"
  />

</TwoLineListItem>


android.R.layout.simple_list_item_checked
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height=
  "?android:attr/listPreferredItemHeightSmall"
  android:textAppearance=
  "?android:attr/textAppearanceListItemSmall"
  android:gravity="center_vertical"
  android:checkMark="?android:attr/textCheckMark"
  android:paddingStart=
  "?android:attr/listPreferredItemPaddingStart"
  android:paddingEnd=
  "?android:attr/listPreferredItemPaddingEnd"
/>


android.R.layout.simple_list_item_multiple_choice
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height=
  "?android:attr/listPreferredItemHeightSmall"
  android:textAppearance=
  "?android:attr/textAppearanceListItemSmall"
  android:gravity="center_vertical"
  android:checkMark=
  "?android:attr/listChoiceIndicatorMultiple"
  android:paddingStart=
  "?android:attr/listPreferredItemPaddingStart"
  android:paddingEnd=
  "?android:attr/listPreferredItemPaddingEnd"
/>


android.R.layout.simple_list_item_single_choice
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height=
  "?android:attr/listPreferredItemHeightSmall"
  android:textAppearance=
  "?android:attr/textAppearanceListItemSmall"
  android:gravity="center_vertical"
  android:checkMark=
  "?android:attr/listChoiceIndicatorSingle"
  android:paddingStart=
  "?android:attr/listPreferredItemPaddingStart"
  android:paddingEnd=
  "?android:attr/listPreferredItemPaddingEnd"
/>


android.R.layout.two_line_list_item
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">

  <TextView android:id="@android:id/text1"
  android:textSize="16sp"
  android:textStyle="bold"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  />

  <TextView android:id="@android:id/text2"
  android:textSize="16sp"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  />

</LinearLayout>

Built-in Android ListView layouts: Part 1

See Part Two here.
Android has several built-in ListView layouts that you can easily use without defining your own layout XML.

The source code needs cleanup and better documentation but it should give you an idea how to use the built-in layout.

android.R.layout.activity_list_item
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:paddingTop="1dip"
  android:paddingBottom="1dip"
  android:paddingStart="8dip"
  android:paddingEnd="8dip">

  <ImageView android:id="@+id/icon"
    android:layout_width="24dip"
    android:layout_height="24dip"
  />

  <TextView android:id="@android:id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:paddingStart=
    "?android:attr/listPreferredItemPaddingStart"
  />
</LinearLayout>


android.R.layout.simple_expandable_list_item_1
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<TextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height=
  "?android:attr/listPreferredItemHeight"
  android:paddingStart=
  "?android:attr/expandableListPreferredItemPaddingLeft"
  android:textAppearance=
  "?android:attr/textAppearanceListItem"
  android:gravity="center_vertical"
/>


android.R.layout.simple_expandable_list_item_2
Source Code: Git | SVN
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem
  xmlns:android=
  "http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent"
  android:layout_height=
  "?android:attr/listPreferredItemHeight"
  android:paddingTop="2dip"
  android:paddingBottom="2dip"
  android:paddingStart=
  "?android:attr/expandableListPreferredItemPaddingLeft"
  android:mode="twoLine"
>

  <TextView android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="6dip"
    android:textAppearance=
    "?android:attr/textAppearanceListItem"
  />

  <TextView android:id="@android:id/text2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@android:id/text1"
    android:layout_alignStart="@android:id/text1"
    android:textAppearance=
    "?android:attr/textAppearanceSmall"
  />

</TwoLineListItem>


android.R.layout.simple_list_item_1
Source Code: Git | SVN | Download Zip | Tutorial
<?xml version="1.0" encoding="utf-8"?>
<TextView
  xmlns:android=
  "http://schemas.android.com/apk/res/android"
  android:id="@android:id/text1"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:textAppearance=
  "?android:attr/textAppearanceListItemSmall"
  android:gravity="center_vertical"
  android:paddingStart=
  "?android:attr/listPreferredItemPaddingStart"
  android:paddingEnd=
  "?android:attr/listPreferredItemPaddingEnd"
  android:minHeight=
  "?android:attr/listPreferredItemHeightSmall"
/>


android.R.layout.simple_list_item_2
Source Code: Git | SVN | Download Zip | Tutorial
<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem
  xmlns:android=
  "http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:minHeight=
  "?android:attr/listPreferredItemHeight"
  android:mode="twoLine"
>
    
  <TextView
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart=
    "?android:attr/listPreferredItemPaddingStart"
    android:layout_marginTop="8dip"
    android:textAppearance=
    "?android:attr/textAppearanceListItem"
  />

  <TextView
    android:id="@android:id/text2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@android:id/text1"
    android:layout_alignStart="@android:id/text1"
    android:textAppearance=
    "?android:attr/textAppearanceSmall"
  />

</TwoLineListItem>

2013-01-22

android:layout_height

Android UI XML Attribute

Name
android:layout_height

Description
Controls the height of the UI element.

Values
Value Description
wrap_contentUI element is automatically sized to fit the UI element content
match_parent UI element is automatically sized to fit the UI element parent container.
fill_parent Deprecated. Functionally identical as match_parent.
#dp Density-independent pixels. Actual size depends on screen resolution of device. The preferred unit to define a specific numeric UI element size. Example usage: 16dp
#sp Scale-independent pixels. Actual size depends on both screen resolution and user's font size settings. Example usage: 16sp
#pt 1/72 of an inch. Example usage: 16pt
#mm A millimeter. Example usage: 16mm
#in An inch. Example usage: 16in
#px A physical pixel. Not recommended to use. Example usage: 16px

Example Usage
<TextView android:layout_height="wrap_content" />

Reference
Android API: layout_height

android:layout_width

Android UI XML Attribute

Name
android:layout_width

Description
Controls the width of the UI element.

Values
Value Description
wrap_contentUI element is automatically sized to fit the UI element content
match_parent UI element is automatically sized to fit the UI element parent container.
fill_parent Deprecated.  Functionally identical as match_parent.
#dp Density-independent pixels. Actual size depends on screen resolution of device.  The preferred unit to define a specific numeric UI element size. Example usage: 16dp
#sp Scale-independent pixels. Actual size depends on both screen resolution and user's font size settings. Example usage: 16sp
#pt 1/72 of an inch. Example usage: 16pt
#mm A millimeter. Example usage: 16mm
#in An inch. Example usage: 16in
#px A physical pixel. Not recommended to use. Example usage: 16px

Example Usage
<TextView android:layout_width="wrap_content" />

Reference
Android API: layout_width