In the previous article (Buttons) of Android developer tutorial we saw different types of buttons available. In the next articles on Android we will do a review of the various controls available for android, Images, labels and for last text boxes.
In this post we will focus on the next user interface controls:
- ImageView
- TextView
- EditText
- ScrollView
ImageView control
ImageView control is capable of displaying the application. The most interesting property is android: src, which lets you specify the image to display. Again, the normal will indicate how the image source of a resource identifier of our portfolio /res/drawable for example android: src = “@drawable/imageexample”. In addition to this property, there are some other useful sometimes those designed to set the maximum size that can take the picture, android:maxWidth and android:maxHeight.
< ImageView android:id= "@+id/ImgPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
In the application logic, we could establish the image by setImageResorce (…), passing the ID of the resource to use as the content of the image.
ImageView img= (ImageView)findViewById(R.id.ImgFoto);
img.setImageResource(R.drawable.icon);
For more information you can visite the next page.
TextView control
The TextView control is another classic in programming GUIs, text labels, and is used to display a given text to the user. As in the case of buttons, the control’s text property is set using the android: text. A part of this property, the nature of control makes the most interesting are those that establish the format of the displayed text, which as in the case of the buttons are as follows: android: background (background color), android: textColor (text color), android: textsize (font size) android: typeface (text style: bold, italic, …).
< TextView android:id= "@+id/Label1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="text label"
android:background="#AA44FF"
android:typeface="monospace"/>
Similarly, we can manipulate these properties from our code. For example, in the following example recover the text of a label with getText (), and then you concatenate a few numbers, update your content via setText () and change its background color with setBackgroundColor ().
< TextView label1= (TextView)findViewById(R.id.Label1);
String text1 = label1.getText().toString();
texto += "este es el texto"
android:text="text label"
label1.setText(text1);
For more information you can visite the next page.
EditText control
EditText control is the text editing component that provides the Android platform. It allows text input and editing by the user, so that design-time most interesting property also establish their position, size and format, the text to display, attribute android: text.
< EditTextandroid:id= "@+id/TxtText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Label1"/>
Similarly, from our code can retrieve and set the text using the methods getText() and setText(Text to set), respectively:
EditText txtText = (EditText)findViewById(R.id.txtText);
String text1 = txtText.getText().toString();
txtText.setText("Text to set");
For more information you can visite the next page.
ScrollView control
Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.
The TextView class also takes care of its own scrolling, so does not require a ScrollView, but using the two together is possible to achieve the effect of a text view within a larger container.
ScrollView only supports vertical scrolling.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView android:id="@+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fillViewport="true">
<TextView android:id="@+id/TEXT_STATUS_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
</ScrollView>
</LinearLayout>
For more information you can visite the next page.