如何在android中使用viewGroup
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1367983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:00:29 来源:igfitidea点击:
How to use viewGroup in android
提问by
How to use viewGroup in android
如何在android中使用viewGroup
回答by worked
As mentioned, ViewGroup is an abstract class that all ViewGroups extend, LinearLayout for instance is a ViewGroup.
如前所述,ViewGroup 是所有 ViewGroup 扩展的抽象类,例如 LinearLayout 是一个 ViewGroup。
MyViewGroup.java:
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:
主要.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:
主活动.java:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}