Info

This would create a TextView object and set its lines and maxlines properties. Attributes come from three sources:

• Attributes exposed directly by the element. For example, TextView supports TextView_text, as discussed above.

• Attributes exposed by all the superclasses of that element. For example, the TextView class extends the View class, so the <TextView> element supports all the attributes that the <View> element exposes — a long list, including View_paddingBottom and View_scrollbars. These too are used without the class name: <TextView android:paddingBottom="20" android:scrollbars="horizontal" />.

• Attributes of the object's ViewGroup.LayoutParams subclass. All View objects support a LayoutParams member (see Declaring Layout). To set properties on an element's LayoutParams member, the attribute to use is "android:layout_layoutParamsProperty". For example: android:layout_gravity for an object wrapped by a <LinearLayout> element. Remember that each LayoutParams subclass also supports inherited attributes. Attributes exposed by each subclass are given in the format someLayoutParamsSubclass_Layout_layout_someproperty. This defines an attribute "android:layout_someproperty". Here is an example of how Android documentation lists the properties of the LinearLayout.LayoutParams class:

• LinearLayout_Layout // The actual object — not used.

• LinearLayout_Layout_layout_gravity // Exposes a gravity attribute

• LinearLayout_Layout_layout_height // Exposes a height attribute

• LinearLayout_Layout_layout_weight // Exposes a weight attribute

• LinearLayout_Layout_layout_width // Exposes a width attribute

Here is an example that sets some of these values on a few objects, including direct attributes, inherited attributes, and LayoutParams attributes:

<?xml version="1.0" encoding="utf-8"?> <!-- res/main screen.xml --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" // The object's own orientation android:padding="4" // Inherited View property android:gravity="center" // The object's own property

// Parent object's LinearLayout.LayoutParams.width AND .height android:layout width="fill parent" android:layout height="fill parent"> <TextView android:layout width="fill parent" //TextView.LayoutParams.width android:layout height="wrap content" //TextView.LayoutParams.height android:layout weight="0" //TextView.LayoutParams.weight android:paddingBottom="4" //TextView.paddingBottom android:text="@string/redirect getter"/> // TextView.text <EditText android:id="@+id/text"

android:layout width="fill parent" //EditText.LayoutParams.width android:layout height="wrap content" //EditText.LayoutParams.height android:layout weight="0" //EditText.LinearLayoutParams.weight android:paddingBottom="4"> //EditText.paddingBottom

<requestFocus /> </EditText>

<Button android:id="@+id/apply"

android:layout width="wrap content" // Button.LayoutParams.width android:layout height="wrap content" // Button.LayoutParams.height android:text="@string/apply" /> // TextView.text

</LinearLayout>

Example Code Use

The most common use is to load the XML file (located at res/main_screen.xml) and use it as the current screen, as shown here with the preceding file:

0 0

Post a comment