Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I use a View node in Android XML layout file?

In Android Studio, I've seen a <View /> node and this has all of Widget's attributes. I'm curious, what's this node and how could I use it?

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/material_cyan_200"
 />
like image 748
Sundy Zhou Avatar asked Sep 24 '15 16:09

Sundy Zhou


2 Answers

  • This class represents the basic building block for user interface components.
  • A View occupies a rectangular area on the screen and is responsible for drawing and event handling.
  • Views are used for Drawing Shapes like Circles,Rectangles,Ovals etc . Just Use View with background and apply a Shape using Custom Drawable.
  • Even Views can be Used a Lines,Place Holders etc

Let me illustrate as per your Example,you have a View Tag as in

<View
    android:id="@+id/myview"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/material_cyan_200"
 />

Which will draw an Horizontal line of Color grey, if suppose you need to make it invisible or some other action,u can do it in .java file as in

View v=findViewById(R.id.myview);
v.setVisible(View.GONE); //will remove View from your UI
like image 192
Rajan Kali Avatar answered Sep 18 '22 22:09

Rajan Kali


An excellent general explanation has been already done by rajan ks.

If you want to know instant usage meaning of the code, I think it would be a thin horizontal border line which colored with @color/material_cyan_200.

like image 34
hata Avatar answered Sep 17 '22 22:09

hata