如何使用的ViewGroup Android中 [英] How to use viewGroup in android

查看:103
本文介绍了如何使用的ViewGroup Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用的ViewGroup在安卓

How to use viewGroup in android

推荐答案

如前所述,一个ViewGroup是一个抽象类,所有ViewGroups延伸的LinearLayout例如是一个ViewGroup中。

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);
    }
}

这篇关于如何使用的ViewGroup Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆