A ViewGroup is a View (inheritance) and a ViewGroup can contain Views (composition). Show activity on this post. Show activity on this post. A ViewGroup is a special view that can contain other views.
ViewGroup is a collection of Views(TextView, EditText, ListView, etc..), somewhat like a container. A View object is a component of the user interface (UI) like a button or a text box, and it's also called a widget.
FindViewById<T>(Int32)Finds a view that was identified by the id attribute from the XML layout resource.
clickable - Defines whether this view reacts to click events. Must be a boolean value, either "true" or "false".
As mentioned, ViewGroup is an abstract class that all ViewGroups extend, LinearLayout for instance is a ViewGroup.
MyViewGroup.java:
public class MyViewGroup extends LinearLayout {
public MyViewGroup(Context context) {
super(context);
}
public MyViewGroup(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyViewGroup(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
Log.e("SWIPED", "onLayout : " + Boolean.toString(changed));
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
super.onInterceptTouchEvent(event);
Log.e("SWIPED", "onInterceptTouchEvent : " + event.getAction());
return false;
}
}
Main.XML:
<com.example.MyViewGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/screen" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="@+id/tv1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="TEXT ONE"
android:padding="20dip" android:background="@android:color/background_dark" />
<TextView android:padding="20dip" android:background="@android:color/background_light"
android:id="@+id/tv2" android:layout_height="wrap_content"
android:text="TEXT TWO" android:layout_width="fill_parent" />
</com.example.MyViewGroup>
MainActivity.java:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With